SleepFutureRunner

Struct SleepFutureRunner 

Source
pub struct SleepFutureRunner<Q, CS>
where CS: TryThreadSpawner<()>,
{ /* private fields */ }
Expand description

Runs asynchronous sleep functions by launching a separate handler thread. Each new instance of this spawns a thread.

Implementations§

Source§

impl<Q, CS> SleepFutureRunner<Q, CS>
where Q: 'static + TimeoutQueue<Item = SleepMessage<CS>> + Send + Sync, CS: TryThreadSpawner<()> + TimeFunctions,

Source

pub fn try_new(queue: Q) -> Result<Self, CS::SpawnError>

Tries to create a new SleepFutureRunner by launching a thread.

Source

pub fn new(queue: Q) -> Self
where CS: ThreadSpawner<()>,

Create a new SleepFutureRunner by launching a thread. Requires thread spawning to be infallible.

Source

pub fn sleep_for(&self, time: Duration) -> impl Future<Output = ()> + '_

Creates a future that sleeps for a given duration from this call.

Source

pub async fn sleep_until(&self, instant: CS::InstantType)

Creates a future that sleeps until a given CS::InstantType.

Source

pub fn timeout_for<'a, T>( &'a self, future: impl Future<Output = T> + 'a, time: Duration, ) -> impl Future<Output = Result<T, ()>> + 'a
where T: 'a,

Runs a given future with a timeout.

Source

pub fn timeout_for_should_stop<'a, T, F>( &'a self, future: impl FnOnce(ShouldFinish) -> F + 'a, time: Duration, ) -> impl Future<Output = Result<T, ()>> + 'a
where T: 'a, F: Future<Output = T> + 'a,

Runs a given future with a timeout. Allows for a should stop parameter.

Source

pub async fn timeout_until<T>( &self, future: impl Future<Output = T>, instant: CS::InstantType, ) -> Result<T, ()>

Runs a given future with a timeout.

Source

pub async fn timeout_until_should_stop<T, F>( &self, future: impl FnOnce(ShouldFinish) -> F, instant: CS::InstantType, ) -> Result<T, ()>
where F: Future<Output = T>,

Runs a given future with a timeout. Allows for a should stop parameter.

Trait Implementations§

Source§

impl<Q: Debug, CS> Debug for SleepFutureRunner<Q, CS>
where CS: TryThreadSpawner<()> + Debug,

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<Q, CS> Freeze for SleepFutureRunner<Q, CS>

§

impl<Q, CS> RefUnwindSafe for SleepFutureRunner<Q, CS>
where Q: RefUnwindSafe,

§

impl<Q, CS> Send for SleepFutureRunner<Q, CS>
where Q: Sync + Send,

§

impl<Q, CS> Sync for SleepFutureRunner<Q, CS>
where Q: Sync + Send,

§

impl<Q, CS> Unpin for SleepFutureRunner<Q, CS>

§

impl<Q, CS> UnwindSafe for SleepFutureRunner<Q, CS>
where Q: RefUnwindSafe,

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> 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, 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.