Files
wren/test/await/await_fn_closure_capture.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

24 lines
576 B
JavaScript
Vendored

// retoor <retoor@molodetz.nl>
import "scheduler" for Scheduler, Future
var multiplier = 10
var scale = async { |x| x * multiplier }
System.print(await scale(5)) // expect: 50
multiplier = 100
System.print(await scale(5)) // expect: 500
var prefix = "Result: "
var format = async { |x| prefix + x.toString }
System.print(await format(42)) // expect: Result: 42
var outer = "outer"
var fn = Fn.new {
var inner = "inner"
var capture = async { |x| outer + "-" + inner + "-" + x }
return await capture("arg")
}
System.print(fn.call()) // expect: outer-inner-arg