gdnative_async/
executor.rs

1use std::cell::Cell;
2
3use futures_task::LocalSpawn;
4
5thread_local!(
6    static LOCAL_SPAWN: Cell<Option<&'static dyn LocalSpawn>> = Cell::new(None);
7);
8
9pub(crate) fn local_spawn() -> Option<&'static dyn LocalSpawn> {
10    LOCAL_SPAWN.with(|cell| cell.get())
11}
12
13/// Sets the global executor for the current thread to a `Box<dyn LocalSpawn>`. This value is leaked.
14pub fn set_boxed_executor(sp: Box<dyn LocalSpawn>) {
15    set_executor(Box::leak(sp))
16}
17
18/// Sets the global executor for the current thread to a `&'static dyn LocalSpawn`.
19pub fn set_executor(sp: &'static dyn LocalSpawn) {
20    LOCAL_SPAWN.with(|cell| cell.set(Some(sp)))
21}