Skip to content

added prioritization intercepter#4878

Open
amyssnippet wants to merge 1 commit intonodejs:mainfrom
amyssnippet:c/4766
Open

added prioritization intercepter#4878
amyssnippet wants to merge 1 commit intonodejs:mainfrom
amyssnippet:c/4766

Conversation

@amyssnippet
Copy link
Contributor

This relates to...

closes / fixes #4766

Rationale

Changes

added priority interceptor with:

  • PriorityQueue — a simple sorted queue with configurable concurrency that dispatches higher-priority requests first
  • PriorityHandler — extends DecoratorHandler, releases the queue slot on response end or error
  • createPriorityInterceptor({ concurrency }) — factory function matching undici's interceptor pattern
  • Requests without opts.priority or without opts.origin bypass the queue entirely
  • Per-origin queues so different origins are scheduled independently

Features

this can be used like the foll code:

const { Client, interceptors } = require('undici')
const client = new Client('http://example.com')
  .compose(interceptors.priority({ concurrency: 1 }))

await client.request({ method: 'GET', path: '/', priority: 10 }) // higher = sooner

Bug Fixes

n/a

Breaking Changes and Deprecations

NA

Status

added tests

@amyssnippet
Copy link
Contributor Author

@mcollina or @ronag should i document this one?? and yes then can i get some guide?

@codecov-commenter
Copy link

codecov-commenter commented Mar 10, 2026

Codecov Report

❌ Patch coverage is 97.77778% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.90%. Comparing base (07276c9) to head (0d0520b).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
lib/interceptor/priority.js 97.72% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4878      +/-   ##
==========================================
- Coverage   93.02%   92.90%   -0.13%     
==========================================
  Files         112      113       +1     
  Lines       35287    35742     +455     
==========================================
+ Hits        32827    33207     +380     
- Misses       2460     2535      +75     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member

@metcoder95 metcoder95 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add TS types and documentation for it

@amyssnippet
Copy link
Contributor Author

@metcoder95 what about the documentation??

@metcoder95
Copy link
Member

can you add documentation for the new interceptor?

@amyssnippet
Copy link
Contributor Author

i added ts types and documentation along with limiting the priorities with

const PRIORITIES = {
  HIGHEST: 4,
  HIGH: 3,
  MEDIUM: 2,
  LOW: 1,
  LOWEST: 0
}

@amyssnippet amyssnippet requested a review from metcoder95 March 12, 2026 13:01
@amyssnippet
Copy link
Contributor Author

the test ci failure is likely a timeout or connection issue on the ci runner

Copy link
Member

@metcoder95 metcoder95 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you push your changes? Current state of the PR hints otherwise

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Request Prioritization Interceptor

3 participants