Function tokio::prelude::task::current [] [src]

pub fn current() -> Task

Returns a handle to the current task to call notify at a later date.

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 current function is called to acquire a handle to the current task, and then the future arranges it such that when the blocking operation otherwise finishes (perhaps in the background) it will notify 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 FutureQueue documentation 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.