pub struct AtomicFuture<'a> { /* private fields */ }
Expand description
A lock-free thread-safe future.
Implementations§
Source§impl<'a> AtomicFuture<'a>
impl<'a> AtomicFuture<'a>
Sourcepub fn new<F: Future<Output = R> + Send + 'a, R: Send + 'a>(
future: F,
detached: bool,
) -> Self
pub fn new<F: Future<Output = R> + Send + 'a, R: Send + 'a>( future: F, detached: bool, ) -> Self
Create a new AtomicFuture
.
Sourcepub unsafe fn new_local<F: Future<Output = R> + 'a, R: 'a>(
future: F,
detached: bool,
) -> Self
pub unsafe fn new_local<F: Future<Output = R> + 'a, R: 'a>( future: F, detached: bool, ) -> Self
Create a new AtomicFuture
from a !Send future.
§Safety
The caller must uphold the Send requirements.
Sourcepub fn try_poll(&self, cx: &mut Context<'_>) -> AttemptPollResult
pub fn try_poll(&self, cx: &mut Context<'_>) -> AttemptPollResult
Attempt to poll the underlying future.
try_poll
ensures that the future is polled at least once more
unless it has already finished.
Sourcepub fn mark_ready(&self) -> bool
pub fn mark_ready(&self) -> bool
Marks the future as ready and returns true if it needs to be added to a run queue, i.e. it isn’t already ready, active or done.
Sourcepub unsafe fn drop_future_unchecked(&self)
pub unsafe fn drop_future_unchecked(&self)
Drops the future without checking its current state.
§Safety
This doesn’t check the current state, so this must only be called if it is known that there is no concurrent access. This also does not include any memory barriers before dropping the future.
Sourcepub fn try_drop(&self) -> Result<(), ()>
pub fn try_drop(&self) -> Result<(), ()>
Drops the future if it is not currently being polled. Returns success if the future was dropped or was already dropped.
Sourcepub fn cancel(&self) -> bool
pub fn cancel(&self) -> bool
Cancels the task. Returns true if the task needs to be added to a run queue.
Sourcepub fn cancel_and_detach(&self) -> CancelAndDetachResult
pub fn cancel_and_detach(&self) -> CancelAndDetachResult
Marks the task as cancelled and detached (for when the caller isn’t interested in waiting for the cancellation to be finished). Returns true if the task should be added to a run queue.
Sourcepub fn is_detached(&self) -> bool
pub fn is_detached(&self) -> bool
Returns true if the task is detached.
Sourcepub unsafe fn take_result<R>(&self) -> Option<R>
pub unsafe fn take_result<R>(&self) -> Option<R>
Trait Implementations§
Source§impl Drop for AtomicFuture<'_>
impl Drop for AtomicFuture<'_>
impl Send for AtomicFuture<'_>
impl Sync for AtomicFuture<'_>
AtomicFuture
is safe to access from multiple threads at once.