mirror of
https://github.com/lune-org/lune.git
synced 2025-04-19 03:13:54 +01: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
|
let mut futs = self
|
||||||
.futures
|
.futures
|
||||||
.try_lock()
|
.try_lock()
|
||||||
.expect("Failed to lock futures for resumption");
|
.expect("Failed to lock futures queue");
|
||||||
while futs.next().await.is_some() {
|
while futs.next().await.is_some() {
|
||||||
resumed_any = true;
|
resumed_any = true;
|
||||||
if self.has_thread() {
|
if self.has_thread() {
|
||||||
|
|
|
@ -14,6 +14,7 @@ mod state;
|
||||||
mod thread;
|
mod thread;
|
||||||
mod traits;
|
mod traits;
|
||||||
|
|
||||||
|
mod impl_async;
|
||||||
mod impl_runner;
|
mod impl_runner;
|
||||||
mod impl_threads;
|
mod impl_threads;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue