Skip to main content

FutureExt

Trait FutureExt 

Source
pub trait FutureExt {
    // Provided methods
    fn with_personality(self, personality: u16) -> WithPersonality<Self> 
       where Self: Sized { ... }
    fn with_cancel(self, token: CancelToken) -> WithCancel<Self> 
       where Self: Sized { ... }
}
Expand description

Extension trait for futures.

§Implementation

Extra data are passed down to runtime when the combinators are polled using a custom Waker, and those data are single-threaded. This means

  • when Wakers are sent to other threads, the data will be lost.
  • when using a “sub-executor” like FuturesUnordered, which also creates its own waker, the data will be lost.

So try to keep the path from the wrapped future to runtime clean, something like this will generally work:

use std::vec::Vec;

use compio::runtime::{FutureExt, CancelToken};
use compio::fs::File;

let file = File::open("/tmp/file");
let cancel = CancelToken::new();
file.read(Vec::with_capacity(1024)).with_cancel(cancel.clone()).await;

Provided Methods§

Source

fn with_personality(self, personality: u16) -> WithPersonality<Self>
where Self: Sized,

Sets the personality for this future.

This only takes effect on io-uring drivers and will be ignored on other ones.

Source

fn with_cancel(self, token: CancelToken) -> WithCancel<Self>
where Self: Sized,

Sets the cancel token for this future.

If multiple CancelTokens are set, the innermost one (the one being polled last) will take precedence.

Implementors§

Source§

impl<F: Future + ?Sized> FutureExt for F