Skip to main content

Task

Struct Task 

Source
pub struct Task { /* private fields */ }
Expand description

A Swift Task this crate started, and owns.

swift_task_create hands the task back at +1 — Swift’s own Task value holds that reference and releases it when the value goes out of scope, and so does this. Dropping the handle while the task is still running is fine: the runtime keeps its own reference until the task completes.

Implementations§

Source§

impl Task

Source

pub fn is_cancelled(&self) -> bool

Has the task been cancelled?

Source

pub fn cancel(&self)

Ask the task to stop.

Cooperative, as in Swift: it sets a flag the body is expected to check with current_task. Nothing is interrupted.

Source

pub fn priority(&self) -> u32

The task’s base priority, as Swift’s TaskPriority numbers it.

Source

pub fn is_finished(&self) -> bool

Has the closure returned?

Does not block. True once the body has run, whether it returned or panicked.

Source

pub fn wait(&self)

Block until the closure has returned.

A Swift Task’s result is delivered by awaiting it, and Rust has nothing to await from — so the entry signals a condition variable on the way out and this waits on it. That makes a detached task usable from ordinary synchronous Rust, which is what it is for here.

Waiting on the executor’s own thread would deadlock, so do not call this from inside another task.

Source

pub fn wait_timeout(&self, limit: Duration) -> bool

wait with a limit. true if the task finished in time.

Trait Implementations§

Source§

impl Drop for Task

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Send for Task

Source§

impl Sync for Task

Auto Trait Implementations§

§

impl Freeze for Task

§

impl RefUnwindSafe for Task

§

impl Unpin for Task

§

impl UnsafeUnpin for Task

§

impl UnwindSafe for Task

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

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

fn try_from(value: U) -> Result<T, !>

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.