kagura 0.8.2

Frontend frame-work for wasm on Rust.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use std::cell::RefCell;

thread_local!(static TASKS: RefCell<Vec<Box<dyn FnOnce()>>> = RefCell::new(vec![]));

pub fn dispatch() {
    let tasks: Vec<_> = TASKS.with(|tasks| tasks.borrow_mut().drain(..).collect());
    for task in tasks {
        task();
    }
}

pub fn add(task: impl FnOnce() + 'static) {
    TASKS.with(|tasks| {
        tasks.borrow_mut().push(Box::new(task));
    });
}