mirror of
https://github.com/lune-org/lune.git
synced 2024-12-12 13:00:37 +00:00
Add api for scheduling plain futures in scheduler
This commit is contained in:
parent
eafc42531f
commit
0a5305b947
3 changed files with 20 additions and 1 deletions
18
src/lune/scheduler/impl_async.rs
Normal file
18
src/lune/scheduler/impl_async.rs
Normal 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))
|
||||
}
|
||||
}
|
|
@ -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() {
|
||||
|
|
|
@ -14,6 +14,7 @@ mod state;
|
|||
mod thread;
|
||||
mod traits;
|
||||
|
||||
mod impl_async;
|
||||
mod impl_runner;
|
||||
mod impl_threads;
|
||||
|
||||
|
|
Loading…
Reference in a new issue