async_engine: move toplevel scheduler into crate
This commit is contained in:
parent
7d9cd198ba
commit
9606e0892c
3 changed files with 7 additions and 6 deletions
|
|
@ -89,7 +89,9 @@ pub mod linkedlist;
|
|||
pub mod line_logger;
|
||||
pub mod object_drop_queue;
|
||||
pub mod pending_serial;
|
||||
pub mod run_toplevel;
|
||||
pub mod run_toplevel {
|
||||
pub use jay_async_engine::RunToplevel;
|
||||
}
|
||||
pub mod scroller;
|
||||
pub mod timer;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,46 +0,0 @@
|
|||
use {
|
||||
crate::{
|
||||
async_engine::{AsyncEngine, SpawnedFuture},
|
||||
utils::queue::AsyncQueue,
|
||||
},
|
||||
std::rc::Rc,
|
||||
};
|
||||
|
||||
pub struct RunToplevelFuture {
|
||||
_future: SpawnedFuture<()>,
|
||||
}
|
||||
|
||||
pub struct RunToplevel {
|
||||
queue: AsyncQueue<Box<dyn FnOnce()>>,
|
||||
}
|
||||
|
||||
impl RunToplevel {
|
||||
pub fn install(eng: &Rc<AsyncEngine>) -> (RunToplevelFuture, Rc<RunToplevel>) {
|
||||
let slf = Rc::new(RunToplevel {
|
||||
queue: Default::default(),
|
||||
});
|
||||
let future = eng.spawn("run toplevel", {
|
||||
let slf = slf.clone();
|
||||
async move {
|
||||
loop {
|
||||
let f = slf.queue.pop().await;
|
||||
f();
|
||||
}
|
||||
}
|
||||
});
|
||||
let future = RunToplevelFuture { _future: future };
|
||||
(future, slf)
|
||||
}
|
||||
|
||||
pub fn schedule<F: FnOnce() + 'static>(&self, f: F) {
|
||||
self.schedule_dyn(Box::new(f));
|
||||
}
|
||||
|
||||
pub fn clear(&self) {
|
||||
self.queue.clear();
|
||||
}
|
||||
|
||||
fn schedule_dyn(&self, f: Box<dyn FnOnce()>) {
|
||||
self.queue.push(f);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue