Examples

Page 9 of 14

goSnippet

Sharded Concurrent Map

Reduce lock contention with a fixed set of independently locked shards, safe for concurrent writes from many goroutines.

goSnippet

Sliding Window Limiter

Track request timestamps in a sliding window to enforce a precise per-interval quota, with an injectable clock for tests.

javascriptSnippet

Async Mutex With FIFO Waiters

Serialize critical sections with an async mutex that queues waiters in FIFO order, supports acquisition timeouts and safe double release.

javascriptSnippet

Cookie Header Parser

Parse a Cookie request header into a null-prototype object, handling quoted values, duplicates and RFC 6265 rules.

javascriptSnippet

Run A Function Only Once

Wrap sync and async functions so initialization runs at most once, sharing the cached result or in-flight promise.

javascriptSnippet

Sliding Window Maximum

Compute the maximum of every fixed-size window in O(n) using a monotonic deque, with clear handling of invalid sizes.