Napi Extensions
This crate extends napi-rs with:
- Local futures runtime
[napi_async]macro for local futuresenv.spawn_local_promise()env.spawn_local()JsPromiseJsRc
Run local futures with:
use *;
use *;
async
Local Thread Futures
Allows for the use of async channels, timers and other async utilities in Rust without blocking the main JavaScript thread while retaining the capability of interacting with the underlying JavaScript values.
Installation
Install the crate with:
cargo add napi_ext
Examples
Timers & Callbacks
use Duration;
use *;
use *;
import napi from './napi.node'
napi.
Channels and Threads
You may combine OS threads with async channels to coordinate off-thread workloads.
I recommend using async_std or async-channel for async utilities as the custom Futures reactor is not compatible with Tokio utilities.
use thread;
use Duration;
use *;
use *;
use channel;
Development
To setup the development environment ensure you have installed just, then run:
npm install
just run example-a