pub(crate) struct OpQueue<Args = (), Output = ()> {
op_requested: Option<(String, Args)>,
op_in_progress: bool,
last_op_result: Option<Output>,
}Expand description
A single-item queue that allows callers to request an operation to be performed later.
ⓘ
let queue = OpQueue::default();
// Request work to be done.
queue.request_op("user pushed a button", ());
// In a later iteration of the server loop, we start the work.
if let Some((_cause, ())) = queue.should_start_op() {
dbg!("Some slow operation here");
}
// In an even later iteration of the server loop, we can see that the work
// was completed.
if !queue.op_in_progress() {
dbg!("Work has been done!");
}Fields§
§op_requested: Option<(String, Args)>§op_in_progress: bool§last_op_result: Option<Output>Implementations§
Source§impl<Args: Debug, Output> OpQueue<Args, Output>
impl<Args: Debug, Output> OpQueue<Args, Output>
Sourcepub(crate) fn request_op(&mut self, reason: String, args: Args)
pub(crate) fn request_op(&mut self, reason: String, args: Args)
Request an operation to start.
Sourcepub(crate) fn should_start_op(&mut self) -> Option<(String, Args)>
pub(crate) fn should_start_op(&mut self) -> Option<(String, Args)>
If there was an operation requested, mark this queue as started and return the request arguments.
Sourcepub(crate) fn op_completed(&mut self, result: Output)
pub(crate) fn op_completed(&mut self, result: Output)
Mark an operation as completed.
Sourcepub(crate) fn last_op_result(&self) -> Option<&Output>
pub(crate) fn last_op_result(&self) -> Option<&Output>
Get the result of the last operation.
pub(crate) fn op_in_progress(&self) -> bool
pub(crate) fn op_requested(&self) -> bool
Trait Implementations§
Auto Trait Implementations§
impl<Args, Output> Freeze for OpQueue<Args, Output>
impl<Args, Output> RefUnwindSafe for OpQueue<Args, Output>where
Output: RefUnwindSafe,
Args: RefUnwindSafe,
impl<Args, Output> Send for OpQueue<Args, Output>
impl<Args, Output> Sync for OpQueue<Args, Output>
impl<Args, Output> Unpin for OpQueue<Args, Output>
impl<Args, Output> UnwindSafe for OpQueue<Args, Output>where
Output: UnwindSafe,
Args: UnwindSafe,
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
§impl<T, R> CollectAndApply<T, R> for T
impl<T, R> CollectAndApply<T, R> for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more