Struct JoinMapBuilder

Source
pub struct JoinMapBuilder<'a, K, V, S> { /* private fields */ }
Available on tokio_unstable and crate feature rt and crate feature tracing only.
Expand description

A variant of task::Builder that spawns tasks on a JoinMap rather than on the current default runtime.

Implementations§

Source§

impl<'a, K, V, S> Builder<'a, K, V, S>
where K: Hash + Eq, V: 'static, S: BuildHasher,

Source

pub fn name(self, name: &'a str) -> Self

Assigns a name to the task which will be spawned.

Source

pub fn spawn<F>(self, key: K, task: F) -> Result<()>
where F: Future<Output = V> + Send + 'static, V: Send,

Spawn the provided task with this builder’s settings and store it in this JoinMap with the provided key.

If a task previously existed in the JoinMap for this key, that task will be cancelled and replaced with the new one. The previous task will be removed from the JoinMap; a subsequent call to join_next will not return a cancelled JoinError for that task.

§Panics

This method panics if called outside of a Tokio runtime.

Source

pub fn spawn_on<F>(&mut self, key: K, task: F, handle: &Handle) -> Result<()>
where F: Future<Output = V> + Send + 'static, V: Send,

Spawn the provided task on the provided runtime and store it in this JoinMap with the provided key.

If a task previously existed in the JoinMap for this key, that task will be cancelled and replaced with the new one. The previous task will be removed from the JoinMap; a subsequent call to join_next will not return a cancelled JoinError for that task.

Source

pub fn spawn_blocking<F>(&mut self, key: K, f: F) -> Result<()>
where F: FnOnce() -> V + Send + 'static, V: Send,

Spawn the blocking code on the blocking threadpool and store it in this JoinMap with the provided key.

If a task previously existed in the JoinMap for this key, that task will be cancelled and replaced with the new one. The previous task will be removed from the JoinMap; a subsequent call to join_next will not return a cancelled JoinError for that task.

Note that blocking tasks cannot be cancelled after execution starts. Replaced blocking tasks will still run to completion if the task has begun to execute when it is replaced. A blocking task which is replaced before it has been scheduled on a blocking worker thread will be cancelled.

§Panics

This method panics if called outside of a Tokio runtime.

Source

pub fn spawn_blocking_on<F>( &mut self, key: K, f: F, handle: &Handle, ) -> Result<()>
where F: FnOnce() -> V + Send + 'static, V: Send,

Spawn the blocking code on the blocking threadpool of the provided runtime and store it in this JoinMap with the provided key.

If a task previously existed in the JoinMap for this key, that task will be cancelled and replaced with the new one. The previous task will be removed from the JoinMap; a subsequent call to join_next will not return a cancelled JoinError for that task.

Note that blocking tasks cannot be cancelled after execution starts. Replaced blocking tasks will still run to completion if the task has begun to execute when it is replaced. A blocking task which is replaced before it has been scheduled on a blocking worker thread will be cancelled.

Source

pub fn spawn_local<F>(&mut self, key: K, task: F) -> Result<()>
where F: Future<Output = V> + 'static,

Spawn the provided task on the current LocalSet and store it in this JoinMap with the provided key.

If a task previously existed in the JoinMap for this key, that task will be cancelled and replaced with the new one. The previous task will be removed from the JoinMap; a subsequent call to join_next will not return a cancelled JoinError for that task.

§Panics

This method panics if it is called outside of a LocalSet.

Source

pub fn spawn_local_on<F>( &mut self, key: K, task: F, local_set: &LocalSet, ) -> Result<()>
where F: Future<Output = V> + 'static,

Spawn the provided task on the provided LocalSet and store it in this JoinMap with the provided key.

If a task previously existed in the JoinMap for this key, that task will be cancelled and replaced with the new one. The previous task will be removed from the JoinMap; a subsequent call to join_next will not return a cancelled JoinError for that task.

Trait Implementations§

Source§

impl<'a, K: Debug, V, S> Debug for Builder<'a, K, V, S>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, K, V, S> Freeze for Builder<'a, K, V, S>

§

impl<'a, K, V, S> !RefUnwindSafe for Builder<'a, K, V, S>

§

impl<'a, K, V, S> Send for Builder<'a, K, V, S>
where S: Send, V: Send, K: Send,

§

impl<'a, K, V, S> Sync for Builder<'a, K, V, S>
where S: Sync, V: Send, K: Sync,

§

impl<'a, K, V, S> Unpin for Builder<'a, K, V, S>

§

impl<'a, K, V, S> !UnwindSafe for Builder<'a, K, V, S>

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.

§

impl<T> Instrument for T

§

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

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

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>,

Source§

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>,

Source§

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.
§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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