devices/virtio/
async_utils.rs

1// Copyright 2021 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//! Virtio device async helper functions.
6
7use anyhow::Context;
8use anyhow::Result;
9use base::Event;
10use cros_async::EventAsync;
11use cros_async::Executor;
12
13/// Async task that waits for a signal from `event`.  Once this event is readable, exit. Exiting
14/// this future will cause the main loop to break and the worker thread to exit.
15pub async fn await_and_exit(ex: &Executor, event: Event) -> Result<()> {
16    let event_async = EventAsync::new(event, ex).context("failed to create EventAsync")?;
17    let _ = event_async.next_val().await;
18    Ok(())
19}