Асинхронный паттерн для долгих операций

engineering

async-task-pattern is a Claude Code skill that converts synchronous operations exceeding 10 seconds into an async state-machine pattern built around triggerAsync() and getStatus(). It targets batch imports of 1,000+ records, bulk remote API calls where batch size × per-call latency exceeds 5 s, full-table scans, and cross-tenant aggregations — any scenario where a synchronous endpoint gets cut off by a 30-second gateway timeout with a 502 or 504. The skill documents five concrete pitfalls with Java/Spring and React code samples: thread blocking by the network gateway, unbounded ConcurrentHashMap growth causing memory leaks (with three eviction strategies — entry-point TTL cleanup, @Scheduled sweep, and Caffeine LRU), ThreadLocal TenantContext loss in child threads, duplicate task spawning from repeated button clicks, and conflicting dual useEffect polling loops on the frontend. Teams dealing with frozen UIs, retry storms, and thread-pool exhaustion get a ready-made state-machine template and a code-review checklist.