contextflight
contextflight
is a thin wrapper around singleflight that adds context handling.
It works like singleflight
, with the addition that the provided function receives a context.Context
, which will be cancelled when all waiting callers' contexts are cancelled.
This allows for correctly cancelling an expensive operation inside of singleflight only when all requesters have canceled their requests.