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`.
29 lines
660 B
JavaScript
Vendored
29 lines
660 B
JavaScript
Vendored
// retoor <retoor@molodetz.nl>
|
|
|
|
import "scheduler" for Scheduler, Future
|
|
|
|
var makeMultiplier = Fn.new { |factor|
|
|
var multiply = async { |x| x * factor }
|
|
return multiply
|
|
}
|
|
|
|
var times2 = makeMultiplier.call(2)
|
|
var times10 = makeMultiplier.call(10)
|
|
|
|
System.print(await times2(5)) // expect: 10
|
|
System.print(await times10(5)) // expect: 50
|
|
|
|
var counter = 0
|
|
var makeCounter = Fn.new {
|
|
var increment = async { |step|
|
|
counter = counter + step
|
|
return counter
|
|
}
|
|
return increment
|
|
}
|
|
|
|
var inc = makeCounter.call()
|
|
System.print(await inc(1)) // expect: 1
|
|
System.print(await inc(5)) // expect: 6
|
|
System.print(await inc(10)) // expect: 16
|