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,
impl<Q, CS> SleepFutureRunner<Q, CS>where
Q: 'static + TimeoutQueue<Item = SleepMessage<CS>> + Send + Sync,
CS: TryThreadSpawner<()> + TimeFunctions,
Sourcepub fn try_new(queue: Q) -> Result<Self, CS::SpawnError>
pub fn try_new(queue: Q) -> Result<Self, CS::SpawnError>
Tries to create a new SleepFutureRunner by launching a thread.
Sourcepub fn new(queue: Q) -> Selfwhere
CS: ThreadSpawner<()>,
pub fn new(queue: Q) -> Selfwhere
CS: ThreadSpawner<()>,
Create a new SleepFutureRunner by launching a thread. Requires thread spawning to be infallible.
Sourcepub fn sleep_for(&self, time: Duration) -> impl Future<Output = ()> + '_
pub fn sleep_for(&self, time: Duration) -> impl Future<Output = ()> + '_
Creates a future that sleeps for a given duration from this call.
Sourcepub async fn sleep_until(&self, instant: CS::InstantType)
pub async fn sleep_until(&self, instant: CS::InstantType)
Creates a future that sleeps until a given CS::InstantType.
Sourcepub fn timeout_for<'a, T>(
&'a self,
future: impl Future<Output = T> + 'a,
time: Duration,
) -> impl Future<Output = Result<T, ()>> + 'awhere
T: 'a,
pub fn timeout_for<'a, T>(
&'a self,
future: impl Future<Output = T> + 'a,
time: Duration,
) -> impl Future<Output = Result<T, ()>> + 'awhere
T: 'a,
Runs a given future with a timeout.
Sourcepub fn timeout_for_should_stop<'a, T, F>(
&'a self,
future: impl FnOnce(ShouldFinish) -> F + 'a,
time: Duration,
) -> impl Future<Output = Result<T, ()>> + 'awhere
T: 'a,
F: Future<Output = T> + 'a,
pub fn timeout_for_should_stop<'a, T, F>(
&'a self,
future: impl FnOnce(ShouldFinish) -> F + 'a,
time: Duration,
) -> impl Future<Output = Result<T, ()>> + 'awhere
T: 'a,
F: Future<Output = T> + 'a,
Runs a given future with a timeout. Allows for a should stop parameter.
Sourcepub async fn timeout_until<T>(
&self,
future: impl Future<Output = T>,
instant: CS::InstantType,
) -> Result<T, ()>
pub async fn timeout_until<T>( &self, future: impl Future<Output = T>, instant: CS::InstantType, ) -> Result<T, ()>
Runs a given future with a timeout.
Sourcepub async fn timeout_until_should_stop<T, F>(
&self,
future: impl FnOnce(ShouldFinish) -> F,
instant: CS::InstantType,
) -> Result<T, ()>where
F: Future<Output = T>,
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§
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>
impl<Q, CS> Sync for SleepFutureRunner<Q, CS>
impl<Q, CS> Unpin for SleepFutureRunner<Q, CS>
impl<Q, CS> UnwindSafe for SleepFutureRunner<Q, CS>where
Q: RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more