feat(task): Task.runToEnd runs a task to its end from synchronous code #344

Merged
argus merged 2 commits from loop/30-task-run-to-end into main 2026-10-12 18:45:33 +00:00
Collaborator

Closes #30

Adds Task<Value>.runToEnd(): Result<Value, Cancelled>, the language/runtime half of #30 as decided on the issue. The client migration of the compiler is #333.

What it does

  • Synchronous code on the main thread calls runToEnd(): torb_scheduler_run(task) runs until that one task has completed, then torb_task_result answers Ok(value) or Fail(Cancelled). This covers a cancel by cancel() and a within whose limit passed.
  • Inside a task, and on any thread other than the main one (an offload body, for example), it panics at the program's call site with a message that names await() / result().
  • A panicking task panics as before.
  • torb_scheduler_run can be called again afterwards. The end-of-program scheduler run still drains tasks nobody waited for.

How

  • It is one native, torb_task_run_to_end (.Fallible, tracks its caller through torb_location), in the C back end.
  • In the VM, the substitute torb_machine_task_run_to_end clears the operating flag around the call, as torb_machine_test_case does.
  • usesTasks counts a call of the native, so a program whose only task use is runToEnd() gets the scheduler.

Tests

  • runtime/tests/task_test.c covers three cases:
    • a sequential call followed by another scheduler run
    • a cancelled task
    • the refusal of a nested call
  • Five conformance programs:
    • task-run-to-end: a std/time sleep, cancel, within, and a late task run at the end of the program
    • task-run-to-end-http: a std/http request against a local server task, from a top level with no await
    • task-run-to-end-in-task: panics inside a task
    • task-run-to-end-offload: panics on a worker
    • task-run-to-end-panic: a panicking task
  • The generated natives files (runtime/machine_natives.c, runtime/include/torb_natives.h) were updated by hand, without a local bootstrap. The natives/bytecode tests in CI check that they match.

Docs

  • CONCURRENCY.md has a new Task.runToEnd section with the single-caller rule, plus a natives table row.
  • docs/standard-library/task.md is updated, and skills/ is regenerated to match.

Seed impact: yes. This is a new native. compiler/src does not use runToEnd yet (that is #333, after a seed refresh).

Closes #30 Adds `Task<Value>.runToEnd(): Result<Value, Cancelled>`, the language/runtime half of #30 as decided on the issue. The client migration of the compiler is #333. **What it does** - Synchronous code on the main thread calls `runToEnd()`: `torb_scheduler_run(task)` runs until that one task has completed, then `torb_task_result` answers `Ok(value)` or `Fail(Cancelled)`. This covers a cancel by `cancel()` and a `within` whose limit passed. - Inside a task, and on any thread other than the main one (an `offload` body, for example), it panics at the program's call site with a message that names `await()` / `result()`. - A panicking task panics as before. - `torb_scheduler_run` can be called again afterwards. The end-of-program scheduler run still drains tasks nobody waited for. **How** - It is one native, `torb_task_run_to_end` (`.Fallible`, tracks its caller through `torb_location`), in the C back end. - In the VM, the substitute `torb_machine_task_run_to_end` clears the operating flag around the call, as `torb_machine_test_case` does. - `usesTasks` counts a call of the native, so a program whose only task use is `runToEnd()` gets the scheduler. **Tests** - runtime/tests/task_test.c covers three cases: - a sequential call followed by another scheduler run - a cancelled task - the refusal of a nested call - Five conformance programs: - `task-run-to-end`: a std/time sleep, cancel, `within`, and a late task run at the end of the program - `task-run-to-end-http`: a std/http request against a local server task, from a top level with no await - `task-run-to-end-in-task`: panics inside a task - `task-run-to-end-offload`: panics on a worker - `task-run-to-end-panic`: a panicking task - The generated natives files (`runtime/machine_natives.c`, `runtime/include/torb_natives.h`) were updated by hand, without a local bootstrap. The natives/bytecode tests in CI check that they match. **Docs** - CONCURRENCY.md has a new `Task.runToEnd` section with the single-caller rule, plus a natives table row. - docs/standard-library/task.md is updated, and skills/ is regenerated to match. **Seed impact: yes.** This is a new native. compiler/src does not use `runToEnd` yet (that is #333, after a seed refresh).
Task.runToEnd() runs the scheduler until its one task has completed and answers what result() would, so a top level that never awaits can still wait for a task. It is one native in both back ends (torb_task_run_to_end, VM substitute torb_machine_task_run_to_end) and panics inside a task or on another thread than the main one. The compiler's own sources do not use it yet (#333).
docs(concurrency): Task.runToEnd and its single caller
Some checks failed
ci / commit messages (pull_request) Successful in 7s
ci / what the change touches (pull_request) Successful in 9s
pdisc / pdisc (pull_request) Successful in 16s
ci / which runners exist (pull_request) Successful in 1s
ci / bootstrap and conformance (windows-x64) (pull_request) Has been skipped
ci / bootstrap and conformance (linux-arm64) (pull_request) Has been skipped
ci / bootstrap and conformance (macos-arm64) (pull_request) Has been skipped
ci / the VS Code extension (editors/vscode) (pull_request) Successful in 18s
ci / bootstrap (linux-x64) (pull_request) Successful in 2m3s
ci / cross-compiled on linux-x64 (windows-x64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (linux-arm64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (macos-arm64) (pull_request) Has been skipped
ci / tier A (linux-x64) (pull_request) Failing after 4m33s
ci / gates (pull_request) Has been cancelled
ci / every host emits the same C (pull_request) Has been cancelled
ci / the playground (torb as WebAssembly) (pull_request) Has been cancelled
ci / pack the seed (pull_request) Has been cancelled
ci / archives (pull_request) Has been cancelled
ci / tier B (linux-x64) (pull_request) Has been cancelled
ci / tools/release-sync and tools/registry (linux-x64) (pull_request) Has been cancelled
0371315ff7
orion force-pushed loop/30-task-run-to-end from 0371315ff7
Some checks failed
ci / commit messages (pull_request) Successful in 7s
ci / what the change touches (pull_request) Successful in 9s
pdisc / pdisc (pull_request) Successful in 16s
ci / which runners exist (pull_request) Successful in 1s
ci / bootstrap and conformance (windows-x64) (pull_request) Has been skipped
ci / bootstrap and conformance (linux-arm64) (pull_request) Has been skipped
ci / bootstrap and conformance (macos-arm64) (pull_request) Has been skipped
ci / the VS Code extension (editors/vscode) (pull_request) Successful in 18s
ci / bootstrap (linux-x64) (pull_request) Successful in 2m3s
ci / cross-compiled on linux-x64 (windows-x64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (linux-arm64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (macos-arm64) (pull_request) Has been skipped
ci / tier A (linux-x64) (pull_request) Failing after 4m33s
ci / gates (pull_request) Has been cancelled
ci / every host emits the same C (pull_request) Has been cancelled
ci / the playground (torb as WebAssembly) (pull_request) Has been cancelled
ci / pack the seed (pull_request) Has been cancelled
ci / archives (pull_request) Has been cancelled
ci / tier B (linux-x64) (pull_request) Has been cancelled
ci / tools/release-sync and tools/registry (linux-x64) (pull_request) Has been cancelled
to cdd87bfe82
Some checks failed
ci / commit messages (pull_request) Successful in 5s
ci / what the change touches (pull_request) Successful in 7s
pdisc / pdisc (pull_request) Successful in 11s
ci / which runners exist (pull_request) Successful in 1s
ci / bootstrap and conformance (windows-x64) (pull_request) Has been skipped
ci / bootstrap and conformance (linux-arm64) (pull_request) Has been skipped
ci / bootstrap and conformance (macos-arm64) (pull_request) Has been skipped
ci / the VS Code extension (editors/vscode) (pull_request) Successful in 18s
ci / bootstrap (linux-x64) (pull_request) Successful in 2m3s
ci / cross-compiled on linux-x64 (windows-x64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (linux-arm64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (macos-arm64) (pull_request) Has been skipped
ci / tier A (linux-x64) (pull_request) Successful in 4m31s
ci / tools/release-sync and tools/registry (linux-x64) (pull_request) Successful in 1m44s
ci / every host emits the same C (pull_request) Successful in 4m39s
ci / tier B (linux-x64) (pull_request) Failing after 10m3s
ci / pack the seed (pull_request) Has been skipped
ci / archives (pull_request) Has been skipped
ci / gates (pull_request) Has been cancelled
ci / the playground (torb as WebAssembly) (pull_request) Has been cancelled
2026-10-12 16:53:53 +00:00
Compare
orion force-pushed loop/30-task-run-to-end from cdd87bfe82
Some checks failed
ci / commit messages (pull_request) Successful in 5s
ci / what the change touches (pull_request) Successful in 7s
pdisc / pdisc (pull_request) Successful in 11s
ci / which runners exist (pull_request) Successful in 1s
ci / bootstrap and conformance (windows-x64) (pull_request) Has been skipped
ci / bootstrap and conformance (linux-arm64) (pull_request) Has been skipped
ci / bootstrap and conformance (macos-arm64) (pull_request) Has been skipped
ci / the VS Code extension (editors/vscode) (pull_request) Successful in 18s
ci / bootstrap (linux-x64) (pull_request) Successful in 2m3s
ci / cross-compiled on linux-x64 (windows-x64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (linux-arm64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (macos-arm64) (pull_request) Has been skipped
ci / tier A (linux-x64) (pull_request) Successful in 4m31s
ci / tools/release-sync and tools/registry (linux-x64) (pull_request) Successful in 1m44s
ci / every host emits the same C (pull_request) Successful in 4m39s
ci / tier B (linux-x64) (pull_request) Failing after 10m3s
ci / pack the seed (pull_request) Has been skipped
ci / archives (pull_request) Has been skipped
ci / gates (pull_request) Has been cancelled
ci / the playground (torb as WebAssembly) (pull_request) Has been cancelled
to 34814ae32b
All checks were successful
ci / every host emits the same C (pull_request) Successful in 4m24s
ci / the playground (torb as WebAssembly) (pull_request) Successful in 1m46s
ci / tier B (linux-x64) (pull_request) Successful in 14m21s
ci / pack the seed (pull_request) Has been skipped
ci / archives (pull_request) Has been skipped
ci / gates (pull_request) Successful in 0s
images / cr.torb.dev/torbscript/registry (push) Has been skipped
images / cr.torb.dev/torbscript/release-sync (push) Has been skipped
images / cr.torb.dev/torbscript/site (push) Has been skipped
ci / commit messages (push) Successful in 7s
ci / what the change touches (push) Successful in 7s
ci / which runners exist (push) Successful in 1s
ci / bootstrap and conformance (windows-x64) (push) Has been skipped
ci / bootstrap and conformance (linux-arm64) (push) Has been skipped
ci / bootstrap and conformance (macos-arm64) (push) Has been skipped
pdisc / pdisc (push) Successful in 9s
ci / the VS Code extension (editors/vscode) (push) Successful in 13s
ci / bootstrap (linux-x64) (push) Successful in 2m1s
ci / cross-compiled on linux-x64 (windows-x64) (push) Has been skipped
ci / cross-compiled on linux-x64 (linux-arm64) (push) Has been skipped
ci / cross-compiled on linux-x64 (macos-arm64) (push) Has been skipped
ci / tier A (linux-x64) (push) Successful in 4m17s
images / cr.torb.dev/torbscript/site:edge (main) (push) Successful in 7m5s
ci / tools/release-sync and tools/registry (linux-x64) (push) Successful in 1m33s
ci / every host emits the same C (push) Successful in 4m23s
ci / the playground (torb as WebAssembly) (push) Successful in 1m47s
ci / tier B (linux-x64) (push) Successful in 12m45s
ci / pack the seed (push) Has been skipped
ci / archives (push) Has been skipped
ci / gates (push) Successful in 0s
2026-10-12 17:26:55 +00:00
Compare
argus approved these changes 2026-10-12 18:45:32 +00:00
argus left a comment

Review of 34814ae (CI green on this head, mergeable).

  • Tests: ok. Three runtime tests (repeat call + later main task, cancelled task answers false, nested call panics and the scheduler goes on) and five conformance programs (sequential/cancel/within/late task, http from a top level, in-task, offload, panic). The hand-edited generated natives are covered by the natives/bytecode checks in CI.
  • Correctness: ok. The caller check (non-main worker or scheduler running) comes before torb_scheduler_run and panics at the program site; browser path panics with a clear message; VM substitute clears the operating flag and restores it. usesTasks now sees the call, so a program whose only task use is runToEnd() gets the scheduler.
  • Scope: ok. Matches the decision on #30 (language/runtime half; client migration is #333).
  • Security/data/workflows: nothing touched.
  • Docs: ok. CONCURRENCY.md, standard-library/task.md and the regenerated skills copy; pdisc green.
  • Architecture: one new native in the manifest and the VM substitute table, both documented.

Non-blocking: none. After merge: seed impact is declared; #333 waits for the seed refresh.

Review of 34814ae (CI green on this head, mergeable). - Tests: ok. Three runtime tests (repeat call + later main task, cancelled task answers false, nested call panics and the scheduler goes on) and five conformance programs (sequential/cancel/within/late task, http from a top level, in-task, offload, panic). The hand-edited generated natives are covered by the natives/bytecode checks in CI. - Correctness: ok. The caller check (non-main worker or scheduler running) comes before torb_scheduler_run and panics at the program site; browser path panics with a clear message; VM substitute clears the operating flag and restores it. usesTasks now sees the call, so a program whose only task use is runToEnd() gets the scheduler. - Scope: ok. Matches the decision on #30 (language/runtime half; client migration is #333). - Security/data/workflows: nothing touched. - Docs: ok. CONCURRENCY.md, standard-library/task.md and the regenerated skills copy; pdisc green. - Architecture: one new native in the manifest and the VM substitute table, both documented. Non-blocking: none. After merge: seed impact is declared; #333 waits for the seed refresh.
argus merged commit 34814ae32b into main 2026-10-12 18:45:33 +00:00
argus deleted branch loop/30-task-run-to-end 2026-10-12 18:45:33 +00:00
Sign in to join this conversation.
No reviewers
No labels
loop
ready
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
torbscript/language!344
No description provided.