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`.
25 lines
546 B
JavaScript
Vendored
25 lines
546 B
JavaScript
Vendored
// retoor <retoor@molodetz.nl>
|
|
|
|
import "scheduler" for Scheduler, Future
|
|
|
|
var isPositive = async { |x| x > 0 }
|
|
var getValue = async { |x| x }
|
|
|
|
if (await isPositive(5)) {
|
|
System.print("positive") // expect: positive
|
|
}
|
|
|
|
if (await isPositive(-5)) {
|
|
System.print("unreachable")
|
|
} else {
|
|
System.print("negative") // expect: negative
|
|
}
|
|
|
|
var result = await isPositive(10) ? "yes" : "no"
|
|
System.print(result) // expect: yes
|
|
|
|
while (await getValue(false)) {
|
|
System.print("unreachable")
|
|
}
|
|
System.print("after while") // expect: after while
|