An educational pure functional programming library in TypeScript
1# Task Queue
2
3Background job processing with real cancellation and easy testing.
4
5## The Problem
6
7Background jobs need retries, timeouts, and error handling. In vanilla TypeScript:
8- Promise.race doesn't actually cancel the losing promise
9- Dependencies are hardcoded, making tests awkward
10- Error context gets lost after retries
11
12## Run Both Versions
13
14```bash
15bun run examples/task-queue/without-purus.ts
16bun run examples/task-queue/with-purus.ts
17```
18
19## Without purus
20
21See `without-purus.ts`:
22- Promise.race for timeout (but the job keeps running!)
23- Hardcoded logger - can't mock without a DI framework
24- Errors are `unknown` after retry exhaustion
25
26## With purus
27
28See `with-purus.ts`:
29- timeout() returns cleanup function - job actually stops
30- provide(env) injects dependencies - swap for tests
31- Typed errors preserved through the pipeline
32
33## Key Takeaways
34
35- Return a cleanup function from async() for real cancellation
36- provide() makes testing easy without frameworks
37- catchAll() preserves error context