internal: prepare to store OpQueue results in the queue itself
This commit is contained in:
parent
fab1c06646
commit
7099438e0c
3 changed files with 24 additions and 13 deletions
|
|
@ -81,10 +81,13 @@ pub(crate) struct GlobalState {
|
|||
pub(crate) status: Status,
|
||||
pub(crate) source_root_config: SourceRootConfig,
|
||||
pub(crate) proc_macro_client: Option<ProcMacroClient>,
|
||||
|
||||
pub(crate) workspaces: Arc<Vec<ProjectWorkspace>>,
|
||||
pub(crate) fetch_workspaces_queue: OpQueue<()>,
|
||||
pub(crate) fetch_workspaces_queue: OpQueue<(), ()>,
|
||||
|
||||
pub(crate) workspace_build_data: Option<BuildDataResult>,
|
||||
pub(crate) fetch_build_data_queue: OpQueue<BuildDataCollector>,
|
||||
pub(crate) fetch_build_data_queue: OpQueue<BuildDataCollector, ()>,
|
||||
|
||||
latest_requests: Arc<RwLock<LatestRequests>>,
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,29 +1,37 @@
|
|||
//! Bookkeeping to make sure only one long-running operation is executed.
|
||||
//! Bookkeeping to make sure only one long-running operation is being executed
|
||||
//! at a time.
|
||||
|
||||
pub(crate) struct OpQueue<D> {
|
||||
op_scheduled: Option<D>,
|
||||
pub(crate) struct OpQueue<Args, Output> {
|
||||
op_scheduled: Option<Args>,
|
||||
op_in_progress: bool,
|
||||
last_op_result: Output,
|
||||
}
|
||||
|
||||
impl<D> Default for OpQueue<D> {
|
||||
impl<Args, Output: Default> Default for OpQueue<Args, Output> {
|
||||
fn default() -> Self {
|
||||
Self { op_scheduled: None, op_in_progress: false }
|
||||
Self { op_scheduled: None, op_in_progress: false, last_op_result: Default::default() }
|
||||
}
|
||||
}
|
||||
|
||||
impl<D> OpQueue<D> {
|
||||
pub(crate) fn request_op(&mut self, data: D) {
|
||||
impl<Args, Output> OpQueue<Args, Output> {
|
||||
pub(crate) fn request_op(&mut self, data: Args) {
|
||||
self.op_scheduled = Some(data);
|
||||
}
|
||||
pub(crate) fn should_start_op(&mut self) -> Option<D> {
|
||||
pub(crate) fn should_start_op(&mut self) -> Option<Args> {
|
||||
if self.op_in_progress {
|
||||
return None;
|
||||
}
|
||||
self.op_in_progress = self.op_scheduled.is_some();
|
||||
self.op_scheduled.take()
|
||||
}
|
||||
pub(crate) fn op_completed(&mut self) {
|
||||
pub(crate) fn op_completed(&mut self, result: Output) {
|
||||
assert!(self.op_in_progress);
|
||||
self.op_in_progress = false;
|
||||
self.last_op_result = result;
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
pub(crate) fn last_op_result(&self) -> &Output {
|
||||
&self.last_op_result
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -140,7 +140,7 @@ impl GlobalState {
|
|||
});
|
||||
}
|
||||
pub(crate) fn fetch_build_data_completed(&mut self) {
|
||||
self.fetch_build_data_queue.op_completed()
|
||||
self.fetch_build_data_queue.op_completed(())
|
||||
}
|
||||
|
||||
pub(crate) fn fetch_workspaces_request(&mut self) {
|
||||
|
|
@ -195,7 +195,7 @@ impl GlobalState {
|
|||
});
|
||||
}
|
||||
pub(crate) fn fetch_workspaces_completed(&mut self) {
|
||||
self.fetch_workspaces_queue.op_completed()
|
||||
self.fetch_workspaces_queue.op_completed(())
|
||||
}
|
||||
|
||||
pub(crate) fn switch_workspaces(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue