DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_Mountain/IPC/WindServiceHandlers/UI/LifecycleWhenPhase.rs
1//! Wire method: `lifecycle:whenPhase`.
2//! Awaits `LifecyclePhaseState::PhaseNotify` instead of polling.
3//! Each forward phase transition calls `notify_waiters()`, so callers wake
4//! exactly when the target phase arrives. Hard cap at 30 s.
5
6use std::sync::Arc;
7
8use serde_json::Value;
9
10use crate::{
11 IPC::WindServiceHandlers::Utilities::JsonValueHelpers::arg_u64_or,
12 RunTime::ApplicationRunTime::ApplicationRunTime,
13};
14
15pub async fn Fn(RunTime:Arc<ApplicationRunTime>, Arguments:Vec<Value>) -> Result<Value, String> {
16 let RequestedPhase = arg_u64_or(&Arguments, 0, 1) as u8;
17
18 let Lifecycle = &RunTime.Environment.ApplicationState.Feature.Lifecycle;
19
20 if Lifecycle.GetPhase() >= RequestedPhase {
21 return Ok(Value::Null);
22 }
23
24 let Notify = Lifecycle.PhaseNotify.clone();
25
26 let _ = tokio::time::timeout(std::time::Duration::from_secs(30), async {
27 loop {
28 Notify.notified().await;
29
30 if Lifecycle.GetPhase() >= RequestedPhase {
31 break;
32 }
33 }
34 })
35 .await;
36
37 Ok(Value::Null)
38}