Available on crate feature
worker only.Expand description
Provides a worker thread that can be used to run javascript code in a separate thread through a channel pair It also provides a default worker implementation that can be used without any additional setup:
use rustyscript::{Error, worker::{Worker, DefaultWorker, DefaultWorkerOptions}};
use std::time::Duration;
fn main() -> Result<(), Error> {
let worker = DefaultWorker::new(DefaultWorkerOptions {
default_entrypoint: None,
timeout: Duration::from_secs(5),
..Default::default()
})?;
let result: i32 = worker.eval("5 + 5".to_string())?;
assert_eq!(result, 10);
Ok(())
}Structs§
- Default
Worker - A worker implementation that uses the default runtime This is the simplest way to use the worker, as it requires no additional setup It attempts to provide as much functionality as possible from the standard runtime
- Default
Worker Options - Options for the default worker
- Worker
- A worker thread that can be used to run javascript code in a separate thread Contains a channel pair for communication, and a single runtime instance
- Worker
Pool - A pool of worker threads that can be used to run javascript code in parallel Uses a round-robin strategy to distribute work between workers Each worker is an independent runtime instance
Enums§
- Default
Worker Query - Query types for the default worker
- Default
Worker Response - Response types for the default worker
Traits§
- Inner
Worker - An implementation of the worker trait for a specific runtime This allows flexibility in the runtime used by the worker As well as the types of queries and responses that can be used