async_io::os::windows

Struct Waitable

Source
pub struct Waitable<T>(/* private fields */);
Expand description

A waitable handle registered in the reactor.

Some handles in Windows are “waitable”, which means that they emit a “readiness” signal after some event occurs. This function can be used to wait for such events to occur on a handle. This function can be used in addition to regular socket polling.

Waitable objects include the following:

  • Console inputs
  • Waitable events
  • Mutexes
  • Processes
  • Semaphores
  • Threads
  • Timer

This structure can be used to wait for any of these objects to become ready.

§Implementation

The current implementation waits on the handle by registering it in the application-global Win32 threadpool. However, in the future it may be possible to migrate to an implementation on Windows 10 that uses a mechanism similar to MsgWaitForMultipleObjectsEx.

§Caveats

Read the documentation for the Async type for more information regarding the abilities and caveats with using this type.

Implementations§

Source§

impl<T: AsHandle> Waitable<T>

Source

pub fn new(handle: T) -> Result<Self>

Create a new Waitable around a waitable handle.

§Examples
use std::process::Command;
use async_io::os::windows::Waitable;

// Create a new process to wait for.
let mut child = Command::new("sleep").arg("5").spawn().unwrap();

// Wrap the process in an `Async` object that waits for it to exit.
let process = Waitable::new(child).unwrap();

// Wait for the process to exit.
process.ready().await.unwrap();
Source§

impl<T> Waitable<T>

Source

pub fn get_ref(&self) -> &T

Get a reference to the inner handle.

Source

pub unsafe fn get_mut(&mut self) -> &mut T

Get a mutable reference to the inner handle.

§Safety

The underlying I/O source must not be dropped or moved out using this function.

Source

pub fn into_inner(self) -> Result<T>

Consumes the Waitable, returning the inner handle.

Source

pub fn ready(&self) -> Ready<'_, T>

Waits until the Waitable object is ready.

This method completes when the underlying Waitable object has completed. See the documentation for the Waitable object for more information.

§Examples
use std::process::Command;
use async_io::os::windows::Waitable;

let child = Command::new("sleep").arg("5").spawn()?;
let process = Waitable::new(child)?;

// Wait for the process to exit.
process.ready().await?;
Source

pub fn poll_ready(&self, cx: &mut Context<'_>) -> Poll<Result<()>>

Polls the I/O handle for readiness.

When this method returns Poll::Ready, that means that the OS has delivered a notification that the underlying Waitable object is ready. See the documentation for the Waitable object for more information.

§Caveats

Two different tasks should not call this method concurrently. Otherwise, conflicting tasks will just keep waking each other in turn, thus wasting CPU time.

§Examples
use std::process::Command;
use async_io::os::windows::Waitable;
use futures_lite::future;

let child = Command::new("sleep").arg("5").spawn()?;
let process = Waitable::new(child)?;

// Wait for the process to exit.
future::poll_fn(|cx| process.poll_ready(cx)).await?;

Trait Implementations§

Source§

impl<T: AsHandle> AsHandle for Waitable<T>

Source§

fn as_handle(&self) -> BorrowedHandle<'_>

Borrows the handle. Read more
Source§

impl<T: AsRawHandle> AsRawHandle for Waitable<T>

Source§

fn as_raw_handle(&self) -> RawHandle

Extracts the raw handle. Read more
Source§

impl<T> AsRef<T> for Waitable<T>

Source§

fn as_ref(&self) -> &T

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T: Debug> Debug for Waitable<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: AsHandle + From<OwnedHandle>> TryFrom<OwnedHandle> for Waitable<T>

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(handle: OwnedHandle) -> Result<Self>

Performs the conversion.
Source§

impl<T: Into<OwnedHandle>> TryFrom<Waitable<T>> for OwnedHandle

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: Waitable<T>) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

§

impl<T> Freeze for Waitable<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Waitable<T>
where T: RefUnwindSafe,

§

impl<T> Send for Waitable<T>
where T: Send,

§

impl<T> Sync for Waitable<T>
where T: Sync,

§

impl<T> Unpin for Waitable<T>

§

impl<T> UnwindSafe for Waitable<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> AsWaitable for T
where T: AsHandle + ?Sized,

Source§

fn as_waitable(&self) -> BorrowedHandle<'_>

Returns the raw handle of this waitable.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more