Composable Concurrency With Ref + Deferred
summary
Explains a small concurrency foundation built from Ref (atomic, lock‑free) + Deferred (one‑shot) in Cats Effect/FS2, shows why get+set loses updates and why modify returns a result atomically (CAS loop semantics), builds a memoizing cache that serializes concurrent computes with a Deferred of Either[Throwable,A], and demonstrates interruption-safe recovery by restoring Ref and completing Deferreds (uses uninterruptible regions around the long running task).
AI-written summary · about
chapters (15)
- 0:00Introduction and motivation
- 1:27History and evolution of ref
- 3:12What is a ref?
- 4:57Limitations of ref get and set
- 7:03Introducing ref update and modify
- 9:55Atomic reference and CAS loop
- 16:17What is deferred?
- 19:31Deferred use case with gates
- 25:52Reviewing ref and deferred APIs
- 27:18Why this concurrency scheme?
- 30:54Concurrent state machines
- 34:01Building a memoized cache
- 39:36Handling interruption
- 46:35Summary and applications
- 47:21Q&A
