- executor: coroutines on MoonBit's async intrinsics (%async.suspend / run / capture_cancellation / raise_cancellation_signal), scheduled by a Dispatcher trait (the platform hook) instead of core/async's event loop; works on wasm, wasm-gc, js and native. - Task[T]: wait (re-raises task errors), cancel (unwinds at the next suspension point, running defers; waiters get TaskCancelled), ready, try_result, detach. Executor: spawn, timer, sleep, yield_now, now. - TestDispatcher: deterministic FIFO queue and virtual clock with GPUI's advance_clock semantics (run, then step to each due timer). - app: AsyncApp, App::spawn, Context::spawn (weak handle), foreground/background executors, run_until_parked / advance_clock; App::new() owns a TestDispatcher unless given a dispatcher. - Tests ported/adapted from the scheduler crate; app async tests; the counter example gains a ticker task. Docs: M4 status and deviations. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
12 lines
315 B
MoonBit
12 lines
315 B
MoonBit
///|
|
|
test "panic on waiting outside a task" {
|
|
let dispatcher = TestDispatcher::new()
|
|
let task = Executor::new(dispatcher).timer(1)
|
|
// A coroutine that is not a task: `wait` cannot suspend it.
|
|
run_async(() => {
|
|
capture_cancellation(() => task.wait(), handler=() => ()) catch {
|
|
_ => ()
|
|
}
|
|
})
|
|
}
|