Runs promises with bounded concurrency to avoid overwhelming resources.
// Source: https://github.com/garrytan/gbrain | License: MIT | Copyright 2026 Garry Tan // Provided via justclaw.it.com; keep this notice with the code. /** * Bounded-concurrency Promise.allSettled. * * Runs `fn(item)` for each item with at most `concurrency` in flight at a time. * Returns a `PromiseSettledResult` per input item, in input order, so callers * can distinguish fulfilled-with-result from rejected-with-error per item. * * Used by `gbrain sync --all` (v0.40 Federated Sync v2) to fan out per-source * syncs without overwhelming the embedding API or local disk. * * Why a semaphore + `Promise.allSettled` instead of a library: * - Zero new deps. Bun's stdlib has every primitive we need. * - `Promise.allSettled` semantics are what we want: one source failing * mus ... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key