Crates.io | prokio |
lib.rs | prokio |
version | 0.1.0 |
source | src |
created_at | 2022-10-19 11:11:46.006479 |
updated_at | 2022-10-19 11:11:46.006479 |
description | An asynchronous runtime compatible with WebAssembly and non-WebAssembly targets. |
homepage | |
repository | https://github.com/futursolo/prokio |
max_upload_size | |
id | 691610 |
size | 50,302 |
An asynchronous runtime compatible with WebAssembly and non-WebAssembly targets.
When designing components and libraries that works on both WebAssembly targets backed by JavaScript Runtime and non-WebAssembly targets with Native Runtimes. Developers usually face challenges that requires applying multiple feature flags throughout their application:
Send
futures and WebAssembly types are usually !Send
.To alleviate these issues, Prokio implements a single-threaded runtime that executes ?Send
(Send
or !Send
) futures.
On platforms with multi-threading support, prokio spawns multiple independent runtimes proportional
to the CPU core number. When tasks are spawned with a runtime handle, it will randomly select a
worker thread from the internal pool. All tasks spawned with spawn_local
will run on the same thread
as the thread the task was running. When the runtime runs in a WebAssembly target, all
tasks will be scheduled on the main thread.
This runtime is designed in favour of IO-bounded workload with similar runtime cost. When running I/O workloads, it would produce a slightly better performance as tasks are never moved to another thread. However, If a worker thread is busy, other threads will not be able to steal tasks scheduled on the busy thread. When you have a CPU-bounded task where CPU time is significantly more expensive, it should be spawned with a dedicated thread (or Web Worker) and communicates with the application using channels.
Prokio provides the following components:
Prokio runtime is implemented with different runtimes depending on the target platform and can use all features (timers / IO / task synchronisation) from the selected native runtime:
wasm-bindgen-futures
(WebAssembly targets)tokio
(non-WebAssembly targets)