pub struct SpawnToken<S> { /* private fields */ }
Expand description

在执行器中创建新任务的令牌

当调用任务方法时(比如 #[embassy_executor::task] async fn my_task() { ... }), 返回值是一个的 SpawnToken,它代表这个任务的实例。你必须将它放到一个执行器中去创建任务,如 Spawner::spawn()

范型参数 S 决定执行器在其他线程中是否可以创建任务。如果 S: Send,则可以,这允许将其放到 SendSpawner来生成任务。 否则,就不可以,只能在当前线程中使用 Spawner 来生成任务。

异常

销毁一个 SpawnToken 实例会导致异常。你不该以这种方式“中止”任务的创建。 一旦你调用一个任务函数,并得到一个 SpawnToken,就 必须 创建它。


Token to spawn a newly-created task in an executor.

When calling a task function (like #[embassy_executor::task] async fn my_task() { ... }), the returned value is a SpawnToken that represents an instance of the task, ready to spawn. You must then spawn it into an executor, typically with Spawner::spawn().

The generic parameter S determines whether the task can be spawned in executors in other threads or not. If S: Send, it can, which allows spawning it into a SendSpawner. If not, it can’t, so it can only be spawned into the current thread’s executor, with Spawner.

Panics

Dropping a SpawnToken instance panics. You may not “abort” spawning a task in this way. Once you’ve invoked a task function and obtained a SpawnToken, you must spawn it.

Implementations§

source§

impl<S> SpawnToken<S>

source

pub fn new_failed() -> Self

返回一个 SpawnToken, 代表创建任务失败


Return a SpawnToken that represents a failed spawn.

Trait Implementations§

source§

impl<S> Drop for SpawnToken<S>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<S> !RefUnwindSafe for SpawnToken<S>

§

impl<S> !Send for SpawnToken<S>

§

impl<S> !Sync for SpawnToken<S>

§

impl<S> Unpin for SpawnToken<S>

§

impl<S> !UnwindSafe for SpawnToken<S>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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, U> Into<U> for Twhere 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 Twhere 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 Twhere 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.