Function futures::task::park
[−]
[src]
pub fn park() -> Task
Returns a handle to the current task to call unpark
at a later date.
This function is similar to the standard library's thread::park
function
except that it won't block the current thread but rather the current future
that is being executed.
The returned handle implements the Send
and 'static
bounds and may also
be cheaply cloned. This is useful for squirreling away the handle into a
location which is then later signaled that a future can make progress.
Implementations of the Future
trait typically use this function if they
would otherwise perform a blocking operation. When something isn't ready
yet, this park
function is called to acquire a handle to the current
task, and then the future arranges it such that when the block operation
otherwise finishes (perhaps in the background) it will unpark
the returned
handle.
It's sometimes necessary to pass extra information to the task when
unparking it, so that the task knows something about why it was woken. See
the with_unpark_event
for details on how to do this.
Panics
This function will panic if a task is not currently being executed. That
is, this method can be dangerous to call outside of an implementation of
poll
.