Trait rustyscript::worker::InnerWorker

source ·
pub trait InnerWorker
where Self: Send, Self::RuntimeOptions: Send + 'static + Clone, Self::Query: Send + 'static, Self::Response: Send + 'static,
{ type Runtime; type RuntimeOptions; type Query; type Response; // Required methods fn init_runtime( options: Self::RuntimeOptions, ) -> Result<Self::Runtime, Error>; fn handle_query( runtime: &mut Self::Runtime, query: Self::Query, ) -> Self::Response; // Provided method fn thread( runtime: Self::Runtime, rx: Receiver<Self::Query>, tx: Sender<Self::Response>, ) { ... } }
Expand description

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

Implement this trait for a specific runtime to use it with the worker For an example implementation, see DefaultWorker

Required Associated Types§

source

type Runtime

The type of runtime used by this worker This can just be rustyscript::Runtime if you don’t need to use a custom runtime

source

type RuntimeOptions

The type of options that can be used to initialize the runtime Cannot be rustyscript::RuntimeOptions because it is not Send

source

type Query

The type of query that can be sent to the worker This should be an enum that contains all possible queries

source

type Response

The type of response that can be received from the worker This should be an enum that contains all possible responses

Required Methods§

source

fn init_runtime(options: Self::RuntimeOptions) -> Result<Self::Runtime, Error>

Initialize the runtime used by the worker This should return a new instance of the runtime that will respond to queries

source

fn handle_query( runtime: &mut Self::Runtime, query: Self::Query, ) -> Self::Response

Handle a query sent to the worker Must always return a response of some kind

Provided Methods§

source

fn thread( runtime: Self::Runtime, rx: Receiver<Self::Query>, tx: Sender<Self::Response>, )

The main thread function that will be run by the worker This should handle all incoming queries and send responses back

Object Safety§

This trait is not object safe.

Implementors§