diff options
Diffstat (limited to '')
| -rw-r--r-- | crates/daemon/src/daemon.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/crates/daemon/src/daemon.rs b/crates/daemon/src/daemon.rs index 1c3afcde..70e65c1e 100644 --- a/crates/daemon/src/daemon.rs +++ b/crates/daemon/src/daemon.rs @@ -87,6 +87,20 @@ impl DaemonHandle { tracing::warn!("failed to emit event (no receivers?): {e}"); } } + pub(crate) async fn wait_for(&self, matches: fn(&DaemonEvent) -> bool) -> Result<DaemonEvent> { + let mut rx = self.subscribe(); + loop { + match rx.recv().await { + Ok(e) if matches(&e) => { + return Ok(e); + } + Err(err) => { + return Err(err).context("while waiting for events"); + } + Ok(_) => (), + } + } + } /// Subscribe to the event bus. /// |
