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`.
34 lines
879 B
JavaScript
Vendored
34 lines
879 B
JavaScript
Vendored
// retoor <retoor@molodetz.nl>
|
|
|
|
import "scheduler" for Scheduler, Future
|
|
|
|
class Calculator {
|
|
static add { async { |a, b| a + b } }
|
|
static multiply { async { |a, b| a * b } }
|
|
static square { async { |x| x * x } }
|
|
static constant { async { 42 } }
|
|
|
|
static compute(a, b) {
|
|
var addFn = Calculator.add
|
|
var multiplyFn = Calculator.multiply
|
|
var sum = await addFn(a, b)
|
|
var product = await multiplyFn(a, b)
|
|
return [sum, product]
|
|
}
|
|
}
|
|
|
|
var add = Calculator.add
|
|
System.print(await add(3, 4)) // expect: 7
|
|
|
|
var multiply = Calculator.multiply
|
|
System.print(await multiply(5, 6)) // expect: 30
|
|
|
|
var square = Calculator.square
|
|
System.print(await square(8)) // expect: 64
|
|
|
|
var constant = Calculator.constant
|
|
System.print(await constant()) // expect: 42
|
|
|
|
var results = Calculator.compute(2, 3)
|
|
System.print(results) // expect: [5, 6]
|