fix(container): cache the in-flight promise of an app-scoped binding (GitHub #46)
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>
This commit is contained in:
3 files changed
+67
-10
No files matched your search
@@ -260,6 +260,13 @@ npm treats versions as semver and semver forbids leading zeros.
|
||||
|
||||
### Fixed
|
||||
|
||||
- **An app-scoped binding runs its factory once, however many resolve it at once** (GitHub #46).
|
||||
The internal container cached the value only after the factory settled, so two resolutions that
|
||||
started before then each ran it. It now caches the pending promise. A rejection is still not
|
||||
cached: the next resolution retries, as before, and the callers already waiting share that one
|
||||
rejection. `createApp` was not affected in practice, because it runs each provider once during
|
||||
the memoized boot and registers the finished value, but the container no longer depends on that.
|
||||
|
||||
- **`listen()` rejects when the port is taken** (#138). A bind failure such as `EADDRINUSE` or
|
||||
`EACCES` arrives as the server's `error` event, which `listen()` did not handle: the promise
|
||||
never settled, and the error surfaced as an unhandled one. It now rejects with that error. The
|
||||
|
||||
Reference in new issue
Block a user