rasi_syscall/cancellable.rs
1//! cancelable syscall apis.
2
3use crate::handle::Handle;
4
5/// The returns type of [`WouldBlock`](std::io::ErrorKind::WouldBlock) operations.
6pub enum CancelablePoll<T> {
7 /// Operation is ready, returns operation result.
8 Ready(T),
9 /// Operation is pending, returns operation cancel handle.
10 ///
11 /// When pending handle drops, the syscall implementation should cancel
12 /// the pending operation referenced by this handle.
13 Pending(Handle),
14}
15
16/// Create a ready status of [`CancelablePoll`] from `F: FnOnce() -> T`.
17pub fn ready<T, F>(f: F) -> CancelablePoll<T>
18where
19 F: FnOnce() -> T,
20{
21 CancelablePoll::Ready(f())
22}