Skip to main content

Mountain/IPC/WindServiceHandlers/UI/
LifecycleWhenPhase.rs

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