{"library":"sb-promise-queue","title":"Promise-Queue","description":"sb-promise-queue is a lightweight JavaScript/TypeScript utility library designed to manage and control the concurrency of asynchronous operations using a promise-based queue. Its current stable version is 2.1.1. It allows developers to specify a maximum number of promises that can run simultaneously, preventing resource exhaustion or rate-limiting issues. Key differentiators include its minimalistic and intuitive API, built-in TypeScript type definitions for enhanced developer experience, and clear methods such as `add`, `onIdle`, and `waitTillIdle` for effective task flow management. This library is particularly useful for scenarios requiring controlled execution of potentially resource-intensive async tasks, like API calls or data processing, ensuring stability and performance. While a specific release cadence is not explicitly stated, as a focused utility, updates are generally driven by bug fixes or minor enhancements rather than frequent feature additions.","language":"javascript","status":"active","last_verified":"Tue Apr 21","install":{"commands":["npm install sb-promise-queue"],"cli":null},"imports":["import { PromiseQueue } from 'sb-promise-queue';","import { type Options, PromiseQueue } from 'sb-promise-queue';","const { PromiseQueue } = require('sb-promise-queue');"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { PromiseQueue } from 'sb-promise-queue';\n\nasync function runConcurrentTasks() {\n  const queue = new PromiseQueue({ concurrency: 3 }); // Allow 3 tasks to run concurrently\n  const taskCount = 10;\n  const results: string[] = [];\n\n  console.log(`Starting ${taskCount} tasks with concurrency ${queue.options.concurrency}...`);\n\n  for (let i = 1; i <= taskCount; i++) {\n    queue.add(async () => {\n      console.log(`  [Task ${i}] Started.`);\n      // Simulate an async operation with varying duration\n      await new Promise(resolve => setTimeout(resolve, Math.random() * 1000 + 500));\n      const result = `Task ${i} completed.`;\n      console.log(`  [Task ${i}] Finished.`);\n      results.push(result);\n      return result;\n    });\n  }\n\n  // Wait for all tasks in the queue to finish\n  await queue.waitTillIdle();\n  console.log('All tasks finished!');\n  console.log('Results:', results);\n}\n\nrunConcurrentTasks();","lang":"typescript","description":"Demonstrates initializing a `PromiseQueue` with a specified concurrency, adding multiple asynchronous tasks, and then waiting for all tasks to complete before proceeding, logging their start and end.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}