Move examples/*.sx and their expected/ snapshots into per-category subfolders (examples/<category>/...). Folder = leading filename token, with ffi-objc/ffi-jni kept whole; filenames are unchanged. The corpus runner and LSP sweep now discover each category's expected/ dir, while issues/ stays flat. Example 1058's repo-root-relative companion import is made file-relative. Path strings embedded in 164 snapshots were regenerated (path-only changes). Test-layout docs in CLAUDE.md updated.
29 lines
1.1 KiB
Plaintext
29 lines
1.1 KiB
Plaintext
// B1.2 — the async ergonomic layer over the `Io` capability, blocking
|
|
// default. `context.io.async(worker, ..args)` runs the worker to completion
|
|
// inline and returns a `.ready` Future($R); `f.await()` yields the result
|
|
// (a value-failable `($R, !IoErr)`, handled with `or`). `context.io.now_ms()`
|
|
// reads the monotonic clock through the same capability.
|
|
//
|
|
// Worker form: a lambda whose params are annotated at the call site
|
|
// (`(a: i64, b: i64) -> i64 => …`); `..args` forwards the call-site
|
|
// arguments to it.
|
|
#import "modules/std.sx";
|
|
|
|
main :: () {
|
|
// Homogeneous args.
|
|
s := context.io.async((a: i64, b: i64) -> i64 => a + b, 40, 2);
|
|
print("sum: {}\n", s.await() or { -1 });
|
|
|
|
// Single arg.
|
|
d := context.io.async((x: i64) -> i64 => x * 2, 21);
|
|
print("double: {}\n", d.await() or { -1 });
|
|
|
|
// Nullary worker — the variadic `async` binds an empty pack, so no separate
|
|
// `async_void` entry is needed.
|
|
n := context.io.async(() -> i64 => 42);
|
|
print("nullary: {}\n", n.await() or { -1 });
|
|
|
|
// The Io capability also carries a monotonic clock.
|
|
if context.io.now_ms() >= 0 { print("clock ok\n"); }
|
|
}
|