Add api for scheduling plain futures in scheduler

This commit is contained in:
Filip Tibell 2023-08-16 22:51:40 -05:00
parent eafc42531f
commit 0a5305b947
3 changed files with 20 additions and 1 deletions

View file

@ -0,0 +1,18 @@
use futures_util::Future;
use super::SchedulerImpl;
impl SchedulerImpl {
/**
Schedules a plain future to run whenever the scheduler is available.
*/
pub fn schedule_future<F>(&self, fut: F)
where
F: Future<Output = ()> + 'static,
{
self.futures
.try_lock()
.expect("Failed to lock futures queue")
.push(Box::pin(fut))
}
}

View file

@ -63,7 +63,7 @@ impl SchedulerImpl {
let mut futs = self
.futures
.try_lock()
.expect("Failed to lock futures for resumption");
.expect("Failed to lock futures queue");
while futs.next().await.is_some() {
resumed_any = true;
if self.has_thread() {

View file

@ -14,6 +14,7 @@ mod state;
mod thread;
mod traits;
mod impl_async;
mod impl_runner;
mod impl_threads;