mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-24 00:00:11 +02:00
Add Handle::spawn_fn
Acts as a convenience to avoid `futures::lazy`. Closes #40
This commit is contained in:
+14
-1
@@ -12,7 +12,7 @@ use std::sync::Arc;
|
||||
use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering};
|
||||
use std::time::{Instant, Duration};
|
||||
|
||||
use futures::{Future, IntoFuture, Async};
|
||||
use futures::{self, Future, IntoFuture, Async};
|
||||
use futures::task::{self, Unpark, Task, Spawn};
|
||||
use mio;
|
||||
use slab::Slab;
|
||||
@@ -576,6 +576,19 @@ impl Handle {
|
||||
};
|
||||
inner.borrow_mut().spawn(Box::new(f));
|
||||
}
|
||||
|
||||
/// Spawns a closure on this event loop.
|
||||
///
|
||||
/// This function is a convenience wrapper around the `spawn` function above
|
||||
/// for running a closure wrapped in `futures::lazy`. It will spawn the
|
||||
/// function `f` provided onto the event loop, and continue to run the
|
||||
/// future returned by `f` on the evnet loop as well.
|
||||
pub fn spawn_fn<F, R>(&self, f: F)
|
||||
where F: FnOnce() -> R + 'static,
|
||||
R: IntoFuture<Item=(), Error=()> + 'static,
|
||||
{
|
||||
self.spawn(futures::lazy(f))
|
||||
}
|
||||
}
|
||||
|
||||
impl TimeoutState {
|
||||
|
||||
Reference in New Issue
Block a user