d337ada4d6
- 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
24 lines
551 B
Plaintext
24 lines
551 B
Plaintext
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;
|
|
}
|