pub struct AgnosticExecutorManager { /* private fields */ }Expand description
An AgnosticExecutorManager is configured on creation for a specific executor and it allows you get the the general and local executor, set it as global executor, and of course, start the executor.
Implementations§
Source§impl AgnosticExecutorManager
impl AgnosticExecutorManager
Sourcepub fn get_executor(&self) -> AgnosticExecutor
pub fn get_executor(&self) -> AgnosticExecutor
Get the executor of this manager as an AgnosticExecutor. This is needed if you need to spawn new tasks, and it be easily stored, cloned and send across threads to have it available where ever you need to spawn a new tasks or interact with the executor.
Sourcepub fn get_local_executor(&mut self) -> LocalAgnosticExecutor
pub fn get_local_executor(&mut self) -> LocalAgnosticExecutor
Get the local executor of this manager as a LocalAgnosticExecutor. A local executor is similar to the general executor but it allows to spawn tasks that are not send. The drawback is that, even tough you can store and clone a LocalAgnosticExecutor, you cannot send it to other threads.
Sourcepub fn on_finish<F>(&mut self, cb: F)where
F: FnOnce() + 'static,
pub fn on_finish<F>(&mut self, cb: F)where
F: FnOnce() + 'static,
Sets up a callback to be called when the executor finishes. It can only be called once. This is needed because on wasm the start() call might finish before it’s future completes and we might need a way to detect completion.
Sourcepub fn set_as_global(&self)
pub fn set_as_global(&self)
Sets this executor as the global executor to be used with the global crate functions get_global_executor, spawn and spawn_blocking. You still need to start the executor after setting it as global. This can only be called once.
Sourcepub fn start<F>(self, future: F)
pub fn start<F>(self, future: F)
Start the executor with the provided future. This future doesn’t need to be Send, but it needs to be ’static. You can use async move {…} to achieve this if needed. Note that in wasm the call might finish before the future has completely executed due to the non-blocking nature of the environment, so don’t depend on this. With the other executors you can depend on the fact that start is blocking, but the on_finish callback is called anyway.