Module worker

Module worker 

Source
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§

DefaultWorker
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
DefaultWorkerOptions
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
WorkerPool
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§

DefaultWorkerQuery
Query types for the default worker
DefaultWorkerResponse
Response types for the default worker

Traits§

InnerWorker
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