{"id":46782,"library":"wait-queue","title":"wait-queue","description":"A JavaScript asynchronous queue that implements a producer-consumer pattern using ES6 classes and Promises. Version 1.1.4 (stable) provides methods like push, shift, pop, and unshift where shift and pop return Promises that resolve when items become available. Built on a LinkedList for efficient O(1) operations, it avoids the performance pitfalls of using Array.shift() on large arrays. Main differentiator: it's a lightweight, ready-to-use async queue without external dependencies, supporting both ESM imports and CommonJS requires.","status":"active","version":"1.1.4","language":"javascript","source_language":"en","source_url":"https://github.com/flarestart/wait-queue","tags":["javascript","await","queue","tasks"],"install":[{"cmd":"npm install wait-queue","lang":"bash","label":"npm"},{"cmd":"yarn add wait-queue","lang":"bash","label":"yarn"},{"cmd":"pnpm add wait-queue","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM default export. CommonJS users should use `const WaitQueue = require('wait-queue')`.","wrong":"const { WaitQueue } = require('wait-queue')","symbol":"WaitQueue","correct":"import WaitQueue from 'wait-queue'"},{"note":"TypeScript users import the default export and can supply a type parameter for item type.","wrong":"import { WaitQueue } from 'wait-queue'","symbol":"WaitQueue (TypeScript)","correct":"import WaitQueue from 'wait-queue';\nconst wq = new WaitQueue<string>();"},{"note":"CommonJS uses default require, not destructured. ESM is the primary module system.","wrong":"const { WaitQueue } = require('wait-queue')","symbol":"WaitQueue (CommonJS)","correct":"const WaitQueue = require('wait-queue')"}],"quickstart":{"code":"import WaitQueue from 'wait-queue';\n\nconst wq = new WaitQueue<string>();\n\nasync function worker() {\n  for (let i = 0; i < 5; i++) {\n    const item = await wq.shift();\n    console.log('Processed:', item);\n  }\n}\n\nasync function producer() {\n  const items = ['a', 'b', 'c', 'd', 'e'];\n  for (const item of items) {\n    wq.push(item);\n    console.log('Produced:', item);\n    await new Promise(res => setTimeout(res, 100));\n  }\n}\n\nworker();\nproducer();","lang":"typescript","description":"Demonstrates async producer-consumer pattern using push and shift."},"warnings":[{"fix":"Ensure items are pushed eventually, or use a timeout mechanism (not built-in).","message":"Calling shift() or pop() on an empty queue will cause the Promise to never resolve if no item is ever pushed.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use the provided methods (push, shift, etc.) instead of mutating queue directly.","message":"Do not modify wq.queue (a LinkedList) directly; it may cause unexpected behavior.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"After empty(), call clearListeners() to reject pending shift/pop promises.","message":"The empty() method does not clear listeners; use clearListeners() if you need to cancel waiting promises.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"No API changes, but performance characteristics differ; benchmark your use case.","message":"Version 1.0.0 introduced a breaking change: the internal data structure changed from Array to LinkedList.","severity":"breaking","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'1':50 '1.1.4':21 'array':62 'array.shift':59 'async':73 'asynchron':6 'avail':42 'avoid':53 'await':86 'becom':41 'built':43 'class':17 'commonj':83 'consum':13 'depend':77 'differenti':64 'effici':48 'es6':16 'esm':80 'extern':76 'implement':9 'import':81 'item':40 'javascript':5,85 'larg':61 'lightweight':68 'like':25 'linkedlist':46 'main':63 'method':24 'o':49 'oper':51 'pattern':14 'perform':55 'pitfal':56 'pop':28,34 'produc':12 'producer-consum':11 'promis':19,36 'provid':23 'push':26 'queue':3,7,74,87 'readi':70 'ready-to-us':69 'requir':84 'resolv':38 'return':35 'shift':27,32 'stabl':22 'support':78 'task':88 'unshift':30 'use':15,58,72 'version':20 'wait':2 'wait-queu':1 'without':75","created_at":"2026-06-07T13:01:36.546089+00:00","updated_at":"2026-06-07T13:01:36.546089+00:00","problems":[{"fix":"Use `const WaitQueue = require('wait-queue');` (CommonJS) or `import WaitQueue from 'wait-queue';` (ESM).","cause":"Using destructured require instead of default import/require.","error":"TypeError: WaitQueue is not a constructor"},{"fix":"Run `npm install wait-queue` and use the correct import: `import WaitQueue from 'wait-queue';`.","cause":"Package not installed or import path is wrong.","error":"Cannot find module 'wait-queue'"},{"fix":"Ensure that push() is called somewhere in your code to add items.","cause":"Queue remains empty and no items are ever added.","error":"shift() never resolves"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/flarestart/wait-queue#readme","github":"https://github.com/flarestart/wait-queue","docs":null,"changelog":null,"pypi":null,"npm":"wait-queue","openapi_spec":null,"status_page":null,"smithery":null,"categories":["messaging"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}