pub struct CompleteHandle<T> { /* private fields */ }Available on crate feature
sync only.Expand description
A thread-safe handle to complete the associated CompletableFuture.
It can be safely dropped without setting a completion value.
fn func(complete_handle: CompleteHandle<u32>) {
if let Some(res) = func_that_may_fail() {
// Set the result.
complete_handle.complete(res);
}
// Or just drop the handle.
}If cloned, the handles race to complete the future.
async fn func(complete_handle: CompleteHandle<u32>) {
let clone = complete_handle.clone();
let a = async { complete_handle.complete(1); };
let b = async { clone.complete(2); };
futures::join!(a, b); // The handles race to set the result.
}Implementations§
Trait Implementations§
Source§impl<T> Clone for CompleteHandle<T>
impl<T> Clone for CompleteHandle<T>
Auto Trait Implementations§
impl<T> Freeze for CompleteHandle<T>
impl<T> !RefUnwindSafe for CompleteHandle<T>
impl<T> Send for CompleteHandle<T>where
T: Send,
impl<T> Sync for CompleteHandle<T>where
T: Send,
impl<T> Unpin for CompleteHandle<T>
impl<T> !UnwindSafe for CompleteHandle<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more