mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 21:43:37 +00:00
docs: Add a doc comment for OpQueue
Add an explanatory sentence and some sample code to help readers understand why this struct exists.
This commit is contained in:
parent
32a86cb1da
commit
da907c2ec3
1 changed files with 20 additions and 0 deletions
|
@ -3,6 +3,26 @@
|
||||||
|
|
||||||
pub(crate) type Cause = String;
|
pub(crate) type Cause = String;
|
||||||
|
|
||||||
|
/// 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!");
|
||||||
|
/// }
|
||||||
|
/// ```
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(crate) struct OpQueue<Args = (), Output = ()> {
|
pub(crate) struct OpQueue<Args = (), Output = ()> {
|
||||||
op_requested: Option<(Cause, Args)>,
|
op_requested: Option<(Cause, Args)>,
|
||||||
|
|
Loading…
Reference in a new issue