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`.
This commit is contained in:
Vendored
+54
@@ -0,0 +1,54 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import "scheduler" for Scheduler, Future
|
||||
|
||||
class DataProcessor {
|
||||
static parse { async { |text| text.split(",") } }
|
||||
static filter { async { |list, fn|
|
||||
var result = []
|
||||
for (item in list) {
|
||||
if (fn.call(item)) result.add(item)
|
||||
}
|
||||
return result
|
||||
}}
|
||||
static transform { async { |list, fn|
|
||||
var result = []
|
||||
for (item in list) {
|
||||
result.add(fn.call(item))
|
||||
}
|
||||
return result
|
||||
}}
|
||||
static join { async { |list, sep| list.join(sep) } }
|
||||
|
||||
static pipeline(data) {
|
||||
var parse = DataProcessor.parse
|
||||
var filter = DataProcessor.filter
|
||||
var transform = DataProcessor.transform
|
||||
var join = DataProcessor.join
|
||||
var parsed = await parse(data)
|
||||
var filtered = await filter(parsed) { |s| s.count > 4 }
|
||||
var transformed = await transform(filtered) { |s| s.toList[0] }
|
||||
return await join(transformed, "-")
|
||||
}
|
||||
}
|
||||
|
||||
var data = "apple,banana,cherry,date"
|
||||
|
||||
var parse = DataProcessor.parse
|
||||
var parsed = await parse(data)
|
||||
System.print(parsed) // expect: [apple, banana, cherry, date]
|
||||
|
||||
var filter = DataProcessor.filter
|
||||
var filtered = await filter(parsed) { |s| s.count > 5 }
|
||||
System.print(filtered) // expect: [banana, cherry]
|
||||
|
||||
var transform = DataProcessor.transform
|
||||
var transformed = await transform(filtered) { |s| s.toList[0] }
|
||||
System.print(transformed) // expect: [b, c]
|
||||
|
||||
var join = DataProcessor.join
|
||||
var joined = await join(transformed, "-")
|
||||
System.print(joined) // expect: b-c
|
||||
|
||||
var result = DataProcessor.pipeline("one,two,three,four,five")
|
||||
System.print(result) // expect: t
|
||||
Reference in New Issue
Block a user