An educational pure functional programming library in TypeScript
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

README.md

Task Queue#

Background job processing with real cancellation and easy testing.

The Problem#

Background jobs need retries, timeouts, and error handling. In vanilla TypeScript:

  • Promise.race doesn't actually cancel the losing promise
  • Dependencies are hardcoded, making tests awkward
  • Error context gets lost after retries

Run Both Versions#

bun run examples/task-queue/without-purus.ts
bun run examples/task-queue/with-purus.ts

Without purus#

See without-purus.ts:

  • Promise.race for timeout (but the job keeps running!)
  • Hardcoded logger - can't mock without a DI framework
  • Errors are unknown after retry exhaustion

With purus#

See with-purus.ts:

  • timeout() returns cleanup function - job actually stops
  • provide(env) injects dependencies - swap for tests
  • Typed errors preserved through the pipeline

Key Takeaways#

  • Return a cleanup function from async() for real cancellation
  • provide() makes testing easy without frameworks
  • catchAll() preserves error context