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
impl Task
Sourcepub fn is_cancelled(&self) -> bool
pub fn is_cancelled(&self) -> bool
Has the task been cancelled?
Sourcepub fn cancel(&self)
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.
Sourcepub fn is_finished(&self) -> bool
pub fn is_finished(&self) -> bool
Has the closure returned?
Does not block. True once the body has run, whether it returned or panicked.
Sourcepub fn wait(&self)
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.
Sourcepub fn wait_timeout(&self, limit: Duration) -> bool
pub fn wait_timeout(&self, limit: Duration) -> bool
wait with a limit. true if the task finished in time.