← Back to AILP Home

Async / Await

The async chapter documents Nitpick's Phase 1 async surface as shipped in the v0.31.x cycle: async func: declarations, await <expr> resolution, the compiler-injected executor drain, the borrow rules around suspension points, the Drop interaction, and the spin-poll bridge into the runtime's async file I/O.

This is Phase 1 of 5. The async runtime in src/runtime/async/ (~3,100 lines, predating v0.31) is largely complete, but the user-facing language surface only exposes a narrow slice of it this cycle. Network async, a real awaiter over NitpickFutureHandle, try/catch, and a multi-threaded work-stealing executor are not documented here as if they were available — they are explicit non-goals for v0.31.x.

When to reach for async

You want… Use
Compose calls to other compiled async func:s await
Schedule background work and forget it drop <call>
Read/write a file without blocking the caller thread npk_*_file_async (extern)
Block-style code with synchronous semantics a regular func:
Catch an await-site error as a fallback value defaults / ? / !! / pick
Anything network-shaped Phase 2 (not v0.31.x)

Async is for suspendable composition of work, not parallelism. The Phase 1 executor is single-threaded run-to-completion. The only "real" suspension that lands this cycle is at the machine-instruction level inside coroutine state machines; the file-I/O runtime futures run on a separate 4-thread I/O pool and are observed from user code by polling, not by await.

When not to reach for async

Chapters

  1. README — this page.
  2. Surfaceasync func:, await <expr>, Result<T> at await sites, the compiler-injected npk_executor_run drain.
  3. Errorspass/fail semantics in async bodies, ARIA-040 (await outside an async function), the pulled catch keyword.
  4. Borrows across awaitARIA-041, why borrows don't survive suspension, the Handle<T> escape hatch.
  5. Drop interaction — Drop fires on async completion, on fail unwind, LIFO across nested scopes; the shutdown-of- suspended-task case is deferred.
  6. Async file I/O — the extern + spin-poll surface for npk_write_file_async, npk_read_file_async, npk_file_exists_async, npk_delete_file_async, and the npk_future_is_error disambiguation idiom.
  7. FAQ — known gaps, why no awaiter bridge yet, what Phase 2 and beyond are expected to add.

See also

Validation snapshot (v0.31.0.8)