Files
wren/test/await/await_fn_parallel.wren
T
retoor eadfc8e9cb feat: add await syntax for direct async function calls and new generator/phonebook apps
Add compiler support for calling async functions directly with `await fn(args)` syntax, automatically translating to `await fn.call(args)`. Introduce `create_merge` Makefile target for merging Wren source files. Include new `apps/generator.wren` source code generator using OpenRouter API, `apps/phonebook.wren` CLI phonebook with SQLite backend, and `apps/minitut.md` Wren tutorial reference. Update `example/await_demo.wren` with parameterized async functions, nested awaits, and expression usage. Fix JSON parsing in `example/openrouter_demo.wren` to strip markdown code fences. Document new await syntax in `manual/api/scheduler.html`.
2026-01-25 09:50:20 +00:00

31 lines
640 B
JavaScript
Vendored

// retoor <retoor@molodetz.nl>
import "scheduler" for Scheduler, Future
import "timer" for Timer
var delayedValue = async { |ms, val|
Timer.sleep(ms)
return val
}
var f1 = delayedValue.call(10, "first")
var f2 = delayedValue.call(10, "second")
var f3 = delayedValue.call(10, "third")
System.print(await f1) // expect: first
System.print(await f2) // expect: second
System.print(await f3) // expect: third
var compute = async { |x| x * x }
var futures = []
for (i in 1..5) {
futures.add(compute.call(i))
}
var results = []
for (f in futures) {
results.add(await f)
}
System.print(results) // expect: [1, 4, 9, 16, 25]