Struct tokio_executor::current_thread::CurrentThread

source ·
pub struct CurrentThread<P: Park = ParkThread> { /* private fields */ }
Expand description

Executes tasks on the current thread

Implementations§

source§

impl CurrentThread<ParkThread>

source

pub fn new() -> Self

Create a new instance of CurrentThread.

source§

impl<P: Park> CurrentThread<P>

source

pub fn new_with_park(park: P) -> Self

Create a new instance of CurrentThread backed by the given park handle.

source

pub fn is_idle(&self) -> bool

Returns true if the executor is currently idle.

An idle executor is defined by not currently having any spawned tasks.

Note that this method is inherently racy – if a future is spawned from a remote Handle, this method may return true even though there are more futures to be executed.

source

pub fn spawn<F>(&mut self, future: F) -> &mut Self
where F: Future<Output = ()> + 'static,

Spawn the future on the executor.

This internally queues the future to be executed once run is called.

source

pub fn block_on<F>(&mut self, future: F) -> F::Output
where F: Future,

Synchronously waits for the provided future to complete.

This function can be used to synchronously block the current thread until the provided future has resolved either successfully or with an error. The result of the future is then returned from this function call.

Note that this function will also execute any spawned futures on the current thread, but will not block until these other spawned futures have completed.

The caller is responsible for ensuring that other spawned futures complete execution.

source

pub fn run(&mut self) -> Result<(), RunError>

Run the executor to completion, blocking the thread until all spawned futures have completed.

source

pub fn run_timeout(&mut self, duration: Duration) -> Result<(), RunTimeoutError>

Run the executor to completion, blocking the thread until all spawned futures have completed or duration time has elapsed.

source

pub fn turn(&mut self, duration: Option<Duration>) -> Result<Turn, TurnError>

Perform a single iteration of the event loop.

This function blocks the current thread even if the executor is idle.

source

pub fn get_park(&self) -> &P

Returns a reference to the underlying Park instance.

source

pub fn get_park_mut(&mut self) -> &mut P

Returns a mutable reference to the underlying Park instance.

source

pub fn handle(&self) -> Handle

Get a new handle to spawn futures on the executor

Different to the executor itself, the handle can be sent to different threads and can be used to spawn futures on the executor.

Trait Implementations§

source§

impl<P: Park> Debug for CurrentThread<P>

source§

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<P: Park + Default> Default for CurrentThread<P>

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<P: Park> Drop for CurrentThread<P>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl Executor for CurrentThread

source§

fn spawn( &mut self, future: Pin<Box<dyn Future<Output = ()> + Send>>, ) -> Result<(), SpawnError>

Spawns a future object to run on this executor. Read more
source§

fn status(&self) -> Result<(), SpawnError>

Provides a best effort hint to whether or not spawn will succeed. Read more
source§

impl<T> TypedExecutor<T> for CurrentThread
where T: Future<Output = ()> + 'static,

source§

fn spawn(&mut self, future: T) -> Result<(), SpawnError>

Spawns a future to run on this executor. Read more
source§

fn status(&self) -> Result<(), SpawnError>

Provides a best effort hint to whether or not spawn will succeed. Read more

Auto Trait Implementations§

§

impl<P> Freeze for CurrentThread<P>
where P: Freeze,

§

impl<P = ParkThread> !RefUnwindSafe for CurrentThread<P>

§

impl<P = ParkThread> !Send for CurrentThread<P>

§

impl<P = ParkThread> !Sync for CurrentThread<P>

§

impl<P> Unpin for CurrentThread<P>
where P: Unpin,

§

impl<P = ParkThread> !UnwindSafe for CurrentThread<P>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more