The promise that arrives too late
Concurrent callers duplicate work before an asynchronous cache lookup returns.
What’s going wrong
A memoized async loader must share one in-flight operation per string key. Stdin is {"rounds":[[keys...],...],"results":{key:[{"ok":scalar}|{"error":message},...]}}. Every used key has a nonempty outcome list. Each round starts all listed calls synchronously in order, then waits for all to settle before starting the next round. Cache reads, loads and writes each yield through a promise microtask. One underlying load consumes that key's next planned outcome, repeating the last outcome after the list ends. Fulfilled scalar values are stored in the value cache after the write finishes; rejected loads are never cached. Concurrent callers for one key must receive the same result or error from one operation, including its asynchronous cache lookup and write. Later callers use a fulfilled cached value, or retry after failure. Print {"rounds":[[{"ok":value}|{"error":message},...],...],"loads":[[key,count],...]}; settlements retain call order and load counters retain first-load key order. Scalars include null, false, zero and empty strings. Empty rounds and an empty list of rounds are allowed.
Read one JSON value from stdin and print the specified JSON result to stdout. No actual network or external package is used.
Expected behavior
Reserve in-flight work synchronously across asynchronous cache boundaries while separating cached values from retryable failures.
Reproduction
{"rounds":[["a","a"]],"results":{"a":[{"ok":7}]}}{"rounds":[[{"ok":7},{"ok":7}]],"loads":[["a",1]]}{"rounds":[["a"],["a"]],"results":{"a":[{"ok":7}]}}{"rounds":[[{"ok":7}],[{"ok":7}]],"loads":[["a",1]]}{"rounds":[["a","b"]],"results":{"a":[{"ok":1}],"b":[{"ok":2}]}}{"rounds":[[{"ok":1},{"ok":2}]],"loads":[["a",1],["b",1]]}Before you begin
- Build on connection reservation: the same ownership gap appears when an await yields before a promise is published.
- TypeScript unions, arrays, objects and functions
- Trace runtime behavior even when the program type-checks
Need a nudge?
Reveal one investigation hint at a time. Try each clue before opening the next.
Read the report, then sign in to start your investigation.