sindresorhus / sindresorhus/p-queue

Proposal: `.remove(id)` — dequeue by id with settled promises

Open
#254 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
4.3k
Forks
220
PR merge metrics
No merged PRs in 30d

Description

Adds queue.remove(id), the missing sibling of setPriority(id, priority): tasks gained an id and can be re-ranked, but nothing public can remove one — today removal requires threading an AbortSignal into every add() ahead of time.

Semantics:

  • Removes every QUEUED (not-yet-started) task whose id matches; returns the count removed (0 for an unknown id, no effect).
  • Each removed task's add() promise rejects with the new exported TaskRemovedError (naming the id), and its function is never invoked — no forever-pending promises leaked.
  • Running tasks are never touched; stopping started work remains the AbortSignal's job (the doc says so).
  • size and size-derived observers (onEmpty, onSizeLessThan, sizeBy) see the change immediately; pending, intervals, and concurrency bookkeeping are unaffected.

Internally the removal settles through the same path as a queued-task abort, so there's no second bookkeeping route to drift. Includes node:test coverage (206 → 216 passing) for multi-match removal, unknown ids, promise settlement, running-task survival, and onSizeLessThan interplay, plus tsd type coverage and a readme entry beside setPriority.

Full disclosure: this change was implemented end-to-end by Detent, an autonomous-engineering tool I'm building — every step gated by this repo's own test chain (xo, node:test, tsc, tsd) and independently reviewed before commit. Happy to adjust anything, or to close this in favor of an issue discussion if you prefer that flow.

🤖 Generated with Claude Code


A complete implementation (206 → 216 tests green through xo/node:test/tsc/tsd) is ready on AmineYagoub/p-queue#feat/remove-by-id — GitHub's interaction limits currently prevent me from opening the PR directly; happy to open it the moment that clears, or for a maintainer to pull the branch.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the existing public setPriority(id, priority) API and review the proposed feat/remove-by-id branch, then inspect the README entry, node:test coverage, and tsd type coverage mentioned in the issue. Done means the stated queued-task removal, promise settlement, size-observer behavior, and running-task guarantees are covered while the full xo, node:test, tsc, and tsd chain passes.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.