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 pub mod async_types; 6 pub mod event; 7 pub mod executor; 8 pub mod handle_executor; 9 pub mod handle_source; 10 mod io_completion_port; 11 pub mod overlapped_source; 12 mod timer; 13 pub mod wait_for_handle; 14 use std::future::Future; 15 16 pub use handle_executor::HandleExecutor; 17 pub use handle_executor::HandleExecutorTaskHandle; 18 pub use handle_source::HandleSource; 19 pub use handle_source::HandleWrapper; 20 pub use overlapped_source::OverlappedSource; 21 pub(crate) use wait_for_handle::WaitForHandle; 22 23 use crate::Error; 24 use crate::Result; 25 run_one_handle<F: Future>(fut: F) -> Result<F::Output>26pub fn run_one_handle<F: Future>(fut: F) -> Result<F::Output> { 27 let ex = HandleExecutor::new().map_err(Error::HandleExecutor)?; 28 ex.run_until(fut).map_err(Error::HandleExecutor) 29 } 30 31 /// Creates an Executor that runs one future to completion. 32 /// 33 /// # Example 34 /// 35 /// ``` 36 /// #[cfg(unix)] 37 /// { 38 /// use cros_async::run_one; 39 /// 40 /// let fut = async { 55 }; 41 /// assert_eq!(55, run_one(fut).unwrap()); 42 /// } 43 /// ``` run_one<F: Future>(fut: F) -> Result<F::Output>44pub fn run_one<F: Future>(fut: F) -> Result<F::Output> { 45 run_one_handle(fut) 46 } 47 48 impl From<Error> for std::io::Error { from(e: Error) -> Self49 fn from(e: Error) -> Self { 50 use Error::*; 51 match e { 52 EventAsync(e) => e.into(), 53 HandleExecutor(e) => e.into(), 54 Timer(e) => e.into(), 55 TimerAsync(e) => e.into(), 56 } 57 } 58 } 59