Trait fibers::Spawn [−][src]
pub trait Spawn { fn spawn_boxed(&self, fiber: Box<Future<Item = (), Error = ()> + Send>); fn spawn<F>(&self, fiber: F)
where
F: Future<Item = (), Error = ()> + Send + 'static, { ... } fn spawn_fn<F, T>(&self, f: F)
where
F: FnOnce() -> T + Send + 'static,
T: IntoFuture<Item = (), Error = ()> + Send + 'static,
T::Future: Send, { ... } fn spawn_monitor<F, T, E>(&self, f: F) -> Monitor<T, E>
where
F: Future<Item = T, Error = E> + Send + 'static,
T: Send + 'static,
E: Send + 'static, { ... } fn spawn_link<F, T, E>(&self, f: F) -> Link<(), (), T, E>
where
F: Future<Item = T, Error = E> + Send + 'static,
T: Send + 'static,
E: Send + 'static, { ... } fn boxed(self) -> BoxSpawn
where
Self: Sized + Send + 'static, { ... } }
The Spawn
trait allows for spawning fibers.
Required Methods
fn spawn_boxed(&self, fiber: Box<Future<Item = (), Error = ()> + Send>)
Spawns a fiber which will execute given boxed future.
Provided Methods
fn spawn<F>(&self, fiber: F) where
F: Future<Item = (), Error = ()> + Send + 'static,
F: Future<Item = (), Error = ()> + Send + 'static,
Spawns a fiber which will execute given future.
fn spawn_fn<F, T>(&self, f: F) where
F: FnOnce() -> T + Send + 'static,
T: IntoFuture<Item = (), Error = ()> + Send + 'static,
T::Future: Send,
F: FnOnce() -> T + Send + 'static,
T: IntoFuture<Item = (), Error = ()> + Send + 'static,
T::Future: Send,
Equivalent to self.spawn(futures::lazy(|| f()))
.
fn spawn_monitor<F, T, E>(&self, f: F) -> Monitor<T, E> where
F: Future<Item = T, Error = E> + Send + 'static,
T: Send + 'static,
E: Send + 'static,
F: Future<Item = T, Error = E> + Send + 'static,
T: Send + 'static,
E: Send + 'static,
Spawns a fiber and returns a future to monitor it's execution result.
fn spawn_link<F, T, E>(&self, f: F) -> Link<(), (), T, E> where
F: Future<Item = T, Error = E> + Send + 'static,
T: Send + 'static,
E: Send + 'static,
F: Future<Item = T, Error = E> + Send + 'static,
T: Send + 'static,
E: Send + 'static,
Spawns a linked fiber.
If the returning Link
is dropped, the spawned fiber will terminate.
Examples
use fibers::sync::oneshot; use fibers::{Executor, InPlaceExecutor, Spawn}; use futures::{Future, empty}; let mut executor = InPlaceExecutor::new().unwrap(); let (tx, rx) = oneshot::channel(); let fiber = empty().and_then(move |()| tx.send(())); // Spanws `fiber` and drops `link`. let link = executor.spawn_link(fiber); std::mem::drop(link); // Channel `rx` is disconnected (e.g., `fiber` exited). assert!(executor.run_future(rx).unwrap().is_err());
fn boxed(self) -> BoxSpawn where
Self: Sized + Send + 'static,
Self: Sized + Send + 'static,
Converts this instance into a boxed object.
Implementors
impl Spawn for InPlaceExecutor
impl Spawn for InPlaceExecutorHandle
impl Spawn for ThreadPoolExecutor
impl Spawn for ThreadPoolExecutorHandle
impl Spawn for SchedulerHandle
impl Spawn for BoxSpawn