Files
sx/examples/concurrency/1806-concurrency-io-cancel.sx
agra 66bdc70bf1 test: group examples into per-category folders
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.
2026-06-21 14:41:34 +03:00

18 lines
711 B
Plaintext

// B1.2 — cancellation rides the `!` error channel (model (a)). `f.cancel()`
// sets the per-future cancel flag + marks `state = .canceled`, so a
// subsequent `f.await()` raises `error.Canceled` out of its value-failable
// `($R, !IoErr)` — caught here with `or`. A future that is NOT canceled
// awaits its value normally.
#import "modules/std.sx";
main :: () {
// Not canceled → await yields the value.
ok := context.io.async((n: i64) -> i64 => n, 7);
print("ok: {}\n", ok.await() or { -1 });
// Canceled → await raises .Canceled → the `or` default is taken.
c := context.io.async((n: i64) -> i64 => n, 7);
c.cancel();
print("canceled: {}\n", c.await() or { -99 });
}