feat(task): Task.runToEnd runs a task to its end from synchronous code #344
Loading…
Reference in a new issue
No description provided.
Delete branch "loop/30-task-run-to-end"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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
runToEnd():torb_scheduler_run(task)runs until that one task has completed, thentorb_task_resultanswersOk(value)orFail(Cancelled). This covers a cancel bycancel()and awithinwhose limit passed.offloadbody, for example), it panics at the program's call site with a message that namesawait()/result().torb_scheduler_runcan be called again afterwards. The end-of-program scheduler run still drains tasks nobody waited for.How
torb_task_run_to_end(.Fallible, tracks its caller throughtorb_location), in the C back end.torb_machine_task_run_to_endclears the operating flag around the call, astorb_machine_test_casedoes.usesTaskscounts a call of the native, so a program whose only task use isrunToEnd()gets the scheduler.Tests
task-run-to-end: a std/time sleep, cancel,within, and a late task run at the end of the programtask-run-to-end-http: a std/http request against a local server task, from a top level with no awaittask-run-to-end-in-task: panics inside a tasktask-run-to-end-offload: panics on a workertask-run-to-end-panic: a panicking taskruntime/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
Task.runToEndsection with the single-caller rule, plus a natives table row.Seed impact: yes. This is a new native. compiler/src does not use
runToEndyet (that is #333, after a seed refresh).0371315ff7cdd87bfe82cdd87bfe8234814ae32bReview of
34814ae(CI green on this head, mergeable).Non-blocking: none. After merge: seed impact is declared; #333 waits for the seed refresh.