pub struct CompletableTask<T> { /* private fields */ }
Expand description
A CompletableTask
is a one-time-use shuttle struct to enable tasks/threads
to provide the result of an compute operation. Once the task is completed,
any additional attempts to complete the task results in an error.
This is thread-safe equivalent to OnceCell<T>
, but combines the ability
to block the current thread until the task completes.
Implementations§
Source§impl<T> CompletableTask<T>
impl<T> CompletableTask<T>
Sourcepub fn new() -> CompletableTask<T> ⓘ
pub fn new() -> CompletableTask<T> ⓘ
Creates a new CompletableTask
Sourcepub fn try_complete(&self, value: T) -> Result<(), T>
pub fn try_complete(&self, value: T) -> Result<(), T>
Attempt to complete this task with the specified value.
Returns Ok(())
if the task was successfully completed.
Returns Err(value)
with the provided value if:
- The task has already completed
- Any errors in locking or mutex poisoning prevented the completion
Sourcepub fn is_complete(&self) -> Result<bool, TaskError>
pub fn is_complete(&self) -> Result<bool, TaskError>
Checks if the task has been completed.
- Returns
Ok(true)
if the task has been completed - Returns
Ok(false)
if the task has NOT been completed - Returns
Err(())
if any errors in locking prevented the checks
Sourcepub fn try_take(&self) -> Result<Poll<T>, TaskError>
pub fn try_take(&self) -> Result<Poll<T>, TaskError>
Gets the result of the operation if it has been set. Does NOT block until
the task is complete. Use CompletableTask::take_blocking
for blocking requests.
Returns Ok(Poll::Ready(T))
if the task has been completed
Returns Ok(Poll::Pending))
if the task has NOT been completed
Returns Err(())
if the underlying mutex has been poisoned and is corrupt.
Sourcepub fn take_blocking(&self) -> Result<T, TaskError>
pub fn take_blocking(&self) -> Result<T, TaskError>
Gets the result of the operation, blocking until the operation is complete.
Returns Ok(T)
if the operation completed,
Returns Err(())
if any error happens.
Trait Implementations§
Source§impl<T: Clone> Clone for CompletableTask<T>
impl<T: Clone> Clone for CompletableTask<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more