Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
google
GitHub Repository: google/crosvm
Path: blob/main/base_tokio/src/sys/windows/event.rs
5394 views
1
// Copyright 2024 The ChromiumOS Authors
2
// Use of this source code is governed by a BSD-style license that can be
3
// found in the LICENSE file.
4
5
/// An async version of `base::Event`.
6
pub struct EventTokio(base::Event);
7
8
impl EventTokio {
9
/// Must be a manual-reset event (i.e. created by `base::Event::new()`).
10
///
11
/// TODO: Add support for auto-reset events.
12
pub fn new(event: base::Event) -> anyhow::Result<Self> {
13
Ok(Self(event))
14
}
15
16
/// Blocks until the event is signaled and clears the signal.
17
///
18
/// It is undefined behavior to wait on an event from multiple threads or processes
19
/// simultaneously.
20
pub async fn wait(&self) -> std::io::Result<()> {
21
base::sys::windows::async_wait_for_single_object(&self.0).await?;
22
self.0.reset()?;
23
Ok(())
24
}
25
}
26
27