Struct futures::executor::Spawn
[−]
[src]
pub struct Spawn<T> { /* fields omitted */ }Representation of a spawned future/stream.
This object is returned by the spawn function in this module. This
represents a "fused task and future", storing all necessary pieces of a task
and owning the top-level future that's being driven as well.
A Spawn can be poll'd for completion or execution of the current thread
can be blocked indefinitely until a notification arrives. This can be used
with either futures or streams, with different methods being available on
Spawn depending which is used.
Methods
impl<T> Spawn<T>[src]
fn get_ref(&self) -> &T
Get a shared reference to the object the Spawn is wrapping.
fn get_mut(&mut self) -> &mut T
Get a mutable reference to the object the Spawn is wrapping.
fn into_inner(self) -> T
Consume the Spawn, returning its inner object
impl<F: Future> Spawn<F>[src]
fn poll_future(&mut self, unpark: Arc<Unpark>) -> Poll<F::Item, F::Error>
Polls the internal future, scheduling notifications to be sent to the
unpark argument.
This method will poll the internal future, testing if it's completed
yet. The unpark argument is used as a sink for notifications sent to
this future. That is, while the future is being polled, any call to
task::park() will return a handle that contains the unpark
specified.
If this function returns NotReady, then the unpark should have been
scheduled to receive a notification when poll can be called again.
Otherwise if Ready or Err is returned, the Spawn task can be
safely destroyed.
fn wait_future(&mut self) -> Result<F::Item, F::Error>
Waits for the internal future to complete, blocking this thread's execution until it does.
This function will call poll_future in a loop, waiting for the future
to complete. When a future cannot make progress it will use
thread::park to block the current thread.
fn execute(self, exec: Arc<Executor>) where F: Future<Item=(), Error=()> + Send + 'static
A specialized function to request running a future to completion on the specified executor.
This function only works for futures whose item and error types are ()
and also implement the Send and 'static bounds. This will submit
units of work (instances of Run) to the exec argument provided
necessary to drive the future to completion.
When the future would block, it's arranged that when the future is again
ready it will submit another unit of work to the exec provided. This
will happen in a loop until the future has completed.
This method is not appropriate for all futures, and other kinds of executors typically provide a similar function with perhaps relaxed bounds as well.
impl<S: Stream> Spawn<S>[src]
fn poll_stream(&mut self,
unpark: Arc<Unpark>)
-> Poll<Option<S::Item>, S::Error>
unpark: Arc<Unpark>)
-> Poll<Option<S::Item>, S::Error>
Like poll_future, except polls the underlying stream.
fn wait_stream(&mut self) -> Option<Result<S::Item, S::Error>>
Like wait_future, except only waits for the next element to arrive on
the underlying stream.