Single-flight, generation-checked init for a long-lived resource (an engine
handle, a native bridge, a wasm module).
A boolean plus a cached promise cannot tell "in flight" from "not
started", nor notice a dispose() that landed mid-init: overlapping
init() calls each built a resource (the first leaked), init resumed after
dispose() to resurrect it, and a stale attempt's failure cleared the
promise of the attempt that replaced it. The contract here:
Concurrent init() calls join one in-flight attempt; once ready, init
resolves with the cached value.
A failed attempt is forgotten (failed), so the next init() retries.
dispose() bumps the generation and releases a ready value. An attempt
started under an older generation is stale: its success rejects as
superseded (its value is released, never cached) and its failure touches
nothing. start can poll attempt.isCurrent() to skip building at all.
Dispose is not terminal: the next init() builds afresh.
Single-flight, generation-checked init for a long-lived resource (an engine handle, a native bridge, a wasm module).
A
booleanplus a cached promise cannot tell "in flight" from "not started", nor notice adispose()that landed mid-init: overlappinginit()calls each built a resource (the first leaked), init resumed afterdispose()to resurrect it, and a stale attempt's failure cleared the promise of the attempt that replaced it. The contract here:init()calls join one in-flight attempt; onceready, init resolves with the cached value.failed), so the nextinit()retries.dispose()bumps the generation and releases a ready value. An attempt started under an older generation is stale: its success rejects as superseded (its value is released, never cached) and its failure touches nothing.startcan pollattempt.isCurrent()to skip building at all.init()builds afresh.