partway towards commands

I got very confused and started mucking about with "spawn" when in fact all I needed was the "inline" extension type in orcx that allows the interpreter to expose custom constants.
This commit is contained in:
2026-03-13 16:48:42 +01:00
parent cdcca694c5
commit 09cfcb1839
146 changed files with 3582 additions and 2822 deletions

View File

@@ -1,6 +1,7 @@
use std::cell::RefCell;
use std::num::{NonZero, NonZeroU16};
use std::rc::{Rc, Weak};
use std::time::Duration;
use std::{fmt, ops};
use futures::future::LocalBoxFuture;
@@ -14,12 +15,21 @@ use crate::system::{System, WeakSystem};
use crate::tree::WeakRoot;
pub trait JoinHandle {
/// It is guaranteed that the future will never be polled after this is called
fn abort(&self);
/// take the future out of the task. If the return value
/// is dropped, the spawned future is also dropped
fn join(self: Box<Self>) -> LocalBoxFuture<'static, ()>;
}
pub trait Spawner {
fn spawn_obj(&self, fut: LocalBoxFuture<'static, ()>) -> Box<dyn JoinHandle>;
/// Spawn a future off-task, but in the same thread. If all objects associated
/// with the owning [Ctx] are dropped (eg. expressions, extensions, systems)
/// and no extensions create permanent ref loops, then all tasks will
/// eventually settle, therefore the implementor of this interface should not
/// exit while there are pending tasks to allow external communication
/// channels to cleanly shut down.
fn spawn_obj(&self, delay: Duration, fut: LocalBoxFuture<'static, ()>) -> Box<dyn JoinHandle>;
}
pub struct CtxData {
@@ -58,12 +68,16 @@ impl Ctx {
}
/// Spawn a parallel future that you can join at any later time.
///
/// Don't use this for async Drop, use [orchid_base::stash::stash] instead.
/// Don't use this for async Drop, use [orchid_base::stash] instead.
/// If you use this for an actor object, make sure to actually join the
/// handle.
#[must_use]
pub fn spawn(&self, fut: impl Future<Output = ()> + 'static) -> Box<dyn JoinHandle> {
self.spawner.spawn_obj(Box::pin(fut))
pub fn spawn(
&self,
delay: Duration,
fut: impl Future<Output = ()> + 'static,
) -> Box<dyn JoinHandle> {
self.spawner.spawn_obj(delay, Box::pin(fut))
}
#[must_use]
pub(crate) async fn system_inst(&self, id: api::SysId) -> Option<System> {