Commit Graph
2 Commits
Author SHA1 Message Date
chrnx 510e9c4863 fix(container): cache the in-flight promise of an app-scoped binding (GitHub #46)
CI / dco (pull_request) Successful in 4s
CI / build (pull_request) Successful in 29s
CI / runtimes (bun) (pull_request) Successful in 20s
CI / runtimes (deno) (pull_request) Successful in 33s
CI / runtimes (edge) (pull_request) Successful in 19s
Container.resolve marked an app-scoped binding resolved only after its
factory settled. Two resolutions that started before then both found
nothing cached and both ran the factory, so one token could open two
pools.

The binding now caches the promise as soon as the factory starts, and
every resolution returns that promise. Retry semantics are unchanged:
before, a rejected factory set nothing and the next resolution ran it
again. Now a rejection clears the cached promise, so the next
resolution still retries, and only the callers already waiting on the
failed attempt share its rejection. The factory runs inside an async
wrapper so a synchronous throw takes the same path.

createApp was not exposed to this in practice. bootProvider runs each
provider's runner once, inside the memoized boot, and registers the
finished value as a constant factory, and Container is not exported.
The fix makes the container's own guarantee hold instead of relying on
that.

Refs: GitHub #46
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
2026-10-24 18:31:40 -05:00
chrnx f7098b48ef feat: scope-aware async (transport-agnostic) DI container 2026-06-26 00:38:49 -05:00