pub struct Wait<'wait_list, L: Lock, I, O, OnCancel>where
OnCancel: CancelCallback<'wait_list, L, I, O>,{ /* private fields */ }Expand description
The future of a waiting operation.
This type provides a lower-level API than LockedExclusive::init_and_wait, but is useful
if your guard types are !Send but you still want the outer future to remain Send.
Awaiting and polling this future will panic if you have not called init yet.
Implementations§
Source§impl<'wait_list, L: Lock, I, O, OnCancel> Wait<'wait_list, L, I, O, OnCancel>where
OnCancel: CancelCallback<'wait_list, L, I, O>,
impl<'wait_list, L: Lock, I, O, OnCancel> Wait<'wait_list, L, I, O, OnCancel>where
OnCancel: CancelCallback<'wait_list, L, I, O>,
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new Wait future.
The returned future will be in its “completed” state, so attempting to .await it will
panic unless init is called.
Sourcepub fn is_completed(&self) -> bool
pub fn is_completed(&self) -> bool
Check whether this future is in its completed state or not.
Sourcepub fn init(
self: Pin<&mut Self>,
waker: Waker,
guard: &mut LockedExclusive<'wait_list, L, I, O>,
input: I,
on_cancel: OnCancel,
)
pub fn init( self: Pin<&mut Self>, waker: Waker, guard: &mut LockedExclusive<'wait_list, L, I, O>, input: I, on_cancel: OnCancel, )
Initialize the future, moving it from a completed to waiting state.
This function is mostly only useful inside a poll function (when you have a cx
variable to hand). After calling this, you should return Poll::Pending as the given
waker has been successfully registered in the wait list.
A callback must be supplied to call in the event that the future has been woken but was
cancelled before it could complete. You will often want to re-call
LockedExclusive::wake_one in this case to pass on the notification to someone else.
§Panics
Panics if called on a non-completed future.
Sourcepub fn init_without_waker(
self: Pin<&mut Self>,
guard: &mut LockedExclusive<'wait_list, L, I, O>,
input: I,
on_cancel: OnCancel,
)
pub fn init_without_waker( self: Pin<&mut Self>, guard: &mut LockedExclusive<'wait_list, L, I, O>, input: I, on_cancel: OnCancel, )
The same as init but not requiring a task::Waker, instead substituting in a
temporary no-op waker.
Using this API is always less efficient than writing a poll function manually that calls
init, but it can be useful if you (a) need Send futures but have !Send mutex guards
and (b) want to stay in an async context.