After we started reporting progress when running cargo check during loading, it is possible to crash the client with two identical progress tokens. This points to a deeper issue: we might be running several cargo checks concurrently, which doesn't make sense. This commit linearizes all workspace fetches, making sure no updates are lost. As an additional touch, it also normalizes progress & result reporting, to make sure they stand in sync.
26 lines
643 B
Rust
26 lines
643 B
Rust
//! Bookkeeping to make sure only one long-running operation is executed.
|
|
|
|
#[derive(Default)]
|
|
pub(crate) struct OpQueue {
|
|
op_scheduled: bool,
|
|
op_in_progress: bool,
|
|
}
|
|
|
|
impl OpQueue {
|
|
pub(crate) fn request_op(&mut self) {
|
|
self.op_scheduled = true;
|
|
}
|
|
pub(crate) fn should_start_op(&mut self) -> bool {
|
|
if !self.op_in_progress && self.op_scheduled {
|
|
self.op_in_progress = true;
|
|
self.op_scheduled = false;
|
|
return true;
|
|
}
|
|
false
|
|
}
|
|
pub(crate) fn op_completed(&mut self) {
|
|
assert!(self.op_in_progress);
|
|
self.op_in_progress = false;
|
|
}
|
|
}
|