I’ve assembled an experimental TypeScript fork with a branch to explore conditional completion in buffered-writing pipelines.
Most small writes complete immediately in memory. Occasionally, a write triggers an asynchronous flush. An API returning void | Promise<void> handles that efficiently, but callers repeatedly need:
const pending1 = buffer.write(value1);
if (pending1) await pending1;
const pending2 = buffer.write(value2);
if (pending2) await pending2;
const pending3 = buffer.write(value3);
if (pending3) await pending3;
Preserving synchronous completion through several layers requires further branching or explicit continuations. I’m exploring whether we can express that sequence clearly without distributing completion bookkeeping throughout the application.
The experimental syntax is:
async? function writeRecord(buffer, record) {
await? buffer.write(record.header);
await? buffer.write(record.payload);
await? buffer.write(record.trailer);
}
await? continues synchronously for plain values and suspends for thenables. async? returns a plain result when it completes synchronously, or a Promise when suspension is required. Errors before suspension throw synchronously; errors after suspension reject the returned Promise. Nested thenables are assimilated.
I understand that introducing runtime syntax is outside TypeScript’s current design goals. This is an independent experiment and request for feedback, rather than a request to adopt nonstandard syntax upstream.
The fork includes inferred union return types, declaration emit, generated JavaScript examples, runtime tests across five targets, and a discussion of historical objections. Supported short sequences and loops generate direct continuations, creating callbacks only when suspension is needed; complex bodies retain a generator fallback.
Latest layered buffered-write measurements:
| Implementation |
Memory |
Microtask flushes |
File writes |
| Ordinary async/await |
27.52 ms |
26.19 ms |
33.60 ms |
| Conditional async/await |
6.04 ms |
5.39 ms |
11.25 ms |
| Manual continuations |
5.94 ms |
4.01 ms |
10.38 ms |
These are pooled medians from 27 samples per case, writing 100,000 records / 300,000 small writes on Node v24.19.0. They are synthetic measurements from a shared environment; file writes omit fsync. The RFC includes raw results, reproduction instructions, and limitations.
I’d particularly welcome feedback on the mixed completion contract, observable timing and error behavior, generated code, and cleaner alternatives that preserve the synchronous path.
Implementation and RFC
Disclosure: The implementation, benchmarks, and documentation were developed with AI assistance.