05 / DATA
syncx
A second caller asking for a key while the first is still running waits for that answer instead of issuing a second call, and every one of them receives the same result or the same failure.
WHERE IT SITS
INTERFACE
struct Single[T]structOne call in flight per key: a second caller asking for the same key while the first is still running waits for that answer instead of issuing a second call, and every one of them receives the same result — or the same failure. This is the primitive a cache-aside store is built on: a miss under load must put one query on the database, not one per request.
fn[T] Single::new() -> Single[T]itemAn empty group: no call in flight.
fn[T] Single::len(self : Single[T]) -> Int32itemThe number of calls in flight, which is also the number of keys being shared.
async fn[T] Single::run( self : Single[T], key : String, body : async () -> T) -> TitemRun body for key, or wait for the call already running for it. The caller that runs the body is the one that answers everyone; a body that raises answers them all with the same error, so a failing lookup is not retried once per waiter.