Skip to content

Commit

Permalink
Auto merge of rust-lang#17885 - Wilfred:op_queue_docs, r=lnicola
Browse files Browse the repository at this point in the history
minor: Add a doc comment for OpQueue

Add an explanatory sentence and some sample code to help readers understand why this struct exists.
  • Loading branch information
bors committed Aug 14, 2024
2 parents f96e296 + 5e058db commit 54ecca0
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/tools/rust-analyzer/crates/rust-analyzer/src/op_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,26 @@

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)]
pub(crate) struct OpQueue<Args = (), Output = ()> {
op_requested: Option<(Cause, Args)>,
Expand Down

0 comments on commit 54ecca0

Please sign in to comment.