← ClaudeAtlas

async-flow-controllisted

Async flow control patterns - AbortController cancellation, async iterators for large datasets, worker thread selection, Promise combinator choice, stream backpressure in async pipelines
kookr-ai/kookr · ★ 2 · Data & Documents · score 78
Install: claude install-skill kookr-ai/kookr
# Async Flow Control Patterns Rules for writing async code that cancels cleanly, streams large datasets without OOM, and selects the right concurrency primitive. **Research:** `docs/deepresearch/reports/Async Patterns and Flow Control in Node.js.md` ## Non-Negotiable Rules | # | Rule | Violation Example | Correct Pattern | |---|------|-------------------|-----------------| | 1 | **AbortSignal on long-running ops** | `await fetch(url)` with no timeout | `await fetch(url, { signal })` | | 2 | **Cursor-stream large queries** | `await db.findMany()` on 10K+ rows | Async generator with cursor pagination | | 3 | **`allSettled` for independent ops** | `Promise.all([fetchA(), fetchB()])` where partial OK | `Promise.allSettled([fetchA(), fetchB()])` | | 4 | **Bound concurrency** | `Promise.all(items.map(fn))` unbounded | `Promise.all(items.map(x => limit(() => fn(x))))` | | 5 | **`pipeline()` for streams** | `readable.pipe(writable)` (no error propagation) | `await pipeline(readable, transform, writable)` | | 6 | **CPU work in worker threads** | Heavy computation on main event loop | `worker_threads` pool for CPU, `child_process` for isolation | | 7 | **`try/finally` on async iterators** | Async generator without cleanup | `try { yield* } finally { cursor.close() }` | | 8 | **Respect `drain` on writes** | Ignore `write()` return value | Pause readable on `false`, resume on `drain` | | 9 | **Graceful shutdown on SIGTERM** | Process exits mid-request | Drain in-flight, stop acceptin