Stacked on #4 (base feat/app); the diff shows only M4. Retarget to main once #1–#4 are merged.
What's here
executor, a port of gpui's executor.rs and the scheduler crate, reduced to one thread:
Coroutines use MoonBit's async compiler intrinsics (%async.suspend, %async.run, %async.capture_cancellation, %async.raise_cancellation_signal). They are scheduled through a Dispatcher trait, the platform hook, rather than moonbitlang/core/async's event loop. Core async owns the loop and doesn't support wasm-gc; this runs on all four backends, wasm-gc included.
Task[T]: wait, which re-raises the task's error, and cancel, which resumes the task with a cancellation signal at its next suspension point so its defer blocks run, while waiters get TaskCancelled. Also ready, try_result, is_ready, is_cancelled and detach.
Executor: spawn, timer, sleep, yield_now and now.
TestDispatcher: a deterministic FIFO queue on a virtual clock, with tick, run_until_parked and advance_clock. advance_clock behaves like gpui's: run everything, step to each due timer, repeat.
app integration: AsyncApp (update, update_entity, read_entity, spawn, executors), App::spawn and Context::spawn. The entity task gets a weak handle. App::new() owns a TestDispatcher (like TestAppContext); a platform will pass its own dispatcher. Tests drive it with app.run_until_parked() and app.advance_clock(ms).
The counter example gains a ticker task on the simulated clock, which is then cancelled.
PORTING.md: M4 status, M4 deviations (§6), a corrected async row in the ecosystem table (§3), and toolchain notes (§8).
Deviations
Experimental intrinsics. They sit behind experimental: true, and importers need allow-experimental-packages. They're isolated in src/executor/coroutine.mbt.
One thread. Foreground and background executors are the same; there are no priorities, dedicated threads or block_on.
Tasks aren't cancelled on drop (MoonBit has no Drop); call cancel().
Durations are milliseconds (Int), and now() returns Int64 milliseconds.
No randomized interleaving in the test dispatcher, and no parking detection.
AsyncApp methods return values rather than Results.
Testing
moon check --target all and moon test --target all pass: 124 tests on each of wasm, wasm-gc, js and native.
Executor tests:
Adapted from the scheduler crate: spawn, spawn order, and timer ordering on the virtual clock.
New: awaiting and error propagation, cancel before start, cancel while suspended (unwinding plus waiters notified), cancelled timers, a task cancelling itself, yield_now interleaving, tick.
Abort cases: wait outside a task, and a task waiting for itself.
App tests: tasks that update entities with effects flushed after each update, weak handles across a release, cancelling a spawned task, nested spawn and await, a caller-provided dispatcher, and an abort test.
Stacked on #4 (base `feat/app`); the diff shows only M4. Retarget to `main` once #1–#4 are merged.
## What's here
- **`executor`**, a port of gpui's `executor.rs` and the `scheduler` crate, reduced to one thread:
- **Coroutines** use MoonBit's async compiler intrinsics (`%async.suspend`, `%async.run`, `%async.capture_cancellation`, `%async.raise_cancellation_signal`). They are scheduled through a **`Dispatcher`** trait, the platform hook, rather than `moonbitlang/core/async`'s event loop. Core async owns the loop and doesn't support wasm-gc; this runs on **all four backends, wasm-gc included**.
- **`Task[T]`**: `wait`, which re-raises the task's error, and `cancel`, which resumes the task with a cancellation signal at its next suspension point so its `defer` blocks run, while waiters get `TaskCancelled`. Also `ready`, `try_result`, `is_ready`, `is_cancelled` and `detach`.
- **`Executor`**: `spawn`, `timer`, `sleep`, `yield_now` and `now`.
- **`TestDispatcher`**: a deterministic FIFO queue on a virtual clock, with `tick`, `run_until_parked` and `advance_clock`. `advance_clock` behaves like gpui's: run everything, step to each due timer, repeat.
- **`app` integration**: `AsyncApp` (`update`, `update_entity`, `read_entity`, `spawn`, executors), `App::spawn` and `Context::spawn`. The entity task gets a weak handle. `App::new()` owns a `TestDispatcher` (like `TestAppContext`); a platform will pass its own dispatcher. Tests drive it with `app.run_until_parked()` and `app.advance_clock(ms)`.
- **The counter example** gains a ticker task on the simulated clock, which is then cancelled.
- **PORTING.md**: M4 status, M4 deviations (§6), a corrected async row in the ecosystem table (§3), and toolchain notes (§8).
## Deviations
- **Experimental intrinsics.** They sit behind `experimental: true`, and importers need `allow-experimental-packages`. They're isolated in `src/executor/coroutine.mbt`.
- **One thread.** Foreground and background executors are the same; there are no priorities, dedicated threads or `block_on`.
- **Tasks aren't cancelled on drop** (MoonBit has no `Drop`); call `cancel()`.
- **Durations are milliseconds** (`Int`), and `now()` returns `Int64` milliseconds.
- **No randomized interleaving** in the test dispatcher, and no parking detection.
- **`AsyncApp` methods return values rather than `Result`s.**
## Testing
`moon check --target all` and `moon test --target all` pass: 124 tests on each of wasm, wasm-gc, js and native.
- **Executor tests:**
- Adapted from the scheduler crate: spawn, spawn order, and timer ordering on the virtual clock.
- New: awaiting and error propagation, cancel before start, cancel while suspended (unwinding plus waiters notified), cancelled timers, a task cancelling itself, `yield_now` interleaving, `tick`.
- Abort cases: `wait` outside a task, and a task waiting for itself.
- **App tests**: tasks that update entities with effects flushed after each update, weak handles across a release, cancelling a spawned task, nested spawn and await, a caller-provided dispatcher, and an abort test.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
- 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>
nandi
merged commit 1ae73d13c3 into feat/app2026-11-24 22:42:57 +00:00
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Stacked on #4 (base
feat/app); the diff shows only M4. Retarget tomainonce #1–#4 are merged.What's here
executor, a port of gpui'sexecutor.rsand theschedulercrate, reduced to one thread:%async.suspend,%async.run,%async.capture_cancellation,%async.raise_cancellation_signal). They are scheduled through aDispatchertrait, the platform hook, rather thanmoonbitlang/core/async's event loop. Core async owns the loop and doesn't support wasm-gc; this runs on all four backends, wasm-gc included.Task[T]:wait, which re-raises the task's error, andcancel, which resumes the task with a cancellation signal at its next suspension point so itsdeferblocks run, while waiters getTaskCancelled. Alsoready,try_result,is_ready,is_cancelledanddetach.Executor:spawn,timer,sleep,yield_nowandnow.TestDispatcher: a deterministic FIFO queue on a virtual clock, withtick,run_until_parkedandadvance_clock.advance_clockbehaves like gpui's: run everything, step to each due timer, repeat.appintegration:AsyncApp(update,update_entity,read_entity,spawn, executors),App::spawnandContext::spawn. The entity task gets a weak handle.App::new()owns aTestDispatcher(likeTestAppContext); a platform will pass its own dispatcher. Tests drive it withapp.run_until_parked()andapp.advance_clock(ms).Deviations
experimental: true, and importers needallow-experimental-packages. They're isolated insrc/executor/coroutine.mbt.block_on.Drop); callcancel().Int), andnow()returnsInt64milliseconds.AsyncAppmethods return values rather thanResults.Testing
moon check --target allandmoon test --target allpass: 124 tests on each of wasm, wasm-gc, js and native.yield_nowinterleaving,tick.waitoutside a task, and a task waiting for itself.🤖 Generated with Claude Code