feat: Phase 8.3 async/await syntax + runtime
- AST: declFuncIsAsync flag, ekAwait expression kind - Parser: async func declarations, expr.await postfix operator - Sema: allow await anywhere (blocks current thread until task completes) - HIR: ekAwait lowered to bux_task_join(handle) call - C backend: async func emitted as regular function - Example: examples/async.bux + examples_pkg/async project - All 20 existing examples pass, selfhost build works
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
import Std::Io::{PrintLine, PrintInt};
|
||||
import Std::Task::TaskHandle;
|
||||
|
||||
async func BackgroundWork(id: int) {
|
||||
PrintLine("Task started:");
|
||||
PrintInt(id);
|
||||
PrintLine("");
|
||||
Task_Sleep(50);
|
||||
PrintLine("Task done:");
|
||||
PrintInt(id);
|
||||
PrintLine("");
|
||||
}
|
||||
|
||||
func Main() -> int {
|
||||
PrintLine("Main: spawning tasks...");
|
||||
let h1: *void = spawn BackgroundWork(1);
|
||||
let h2: *void = spawn BackgroundWork(2);
|
||||
PrintLine("Main: waiting for tasks...");
|
||||
h1.await;
|
||||
h2.await;
|
||||
PrintLine("Main: all tasks completed");
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user