Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: replace p-queue with less restrictive queue #2339

Merged
merged 8 commits into from
Jan 6, 2024

Conversation

achingbrain
Copy link
Member

Adds a Queue class to @libp2p/utils modelled on p-queue with a few key differences:

  1. The queue is externally accessible so we can modify it before jobs run
  2. It can be turned into an async generator
  3. Jobs remain in the queue while they are executing for better introspection
  4. It integrates with libp2p metrics, if desired

The dial queue has been replaced with this new queue class, this means we don't need to maintain a separate internal queue for pending dials since the dial queue itself is accessible.

Change checklist

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation if necessary (this includes comments as well)
  • I have added tests that prove my fix is effective or that my feature works

Adds a `Queue` class to `@libp2p/utils` modelled on p-queue with a
few key differences:

1. The queue is externally accessible so we can modify it before jobs run
2. It can be turned into an async generator
3. Jobs remain in the queue while they are executing for better introspection
4. It integrates with libp2p metrics, if desired

The dial queue has been replaced with this new queue class, this means we
don't need to maintain a separate internal queue for pending dials since the
dial queue itself is accessible.
@achingbrain achingbrain requested a review from a team as a code owner December 30, 2023 16:30
achingbrain added a commit that referenced this pull request Dec 30, 2023
Remove extra/add missing deps shown by ipfs/aegir#1426

Depends on #2339
@achingbrain achingbrain mentioned this pull request Dec 30, 2023
3 tasks
await this.onEvent('idle')
}

private async onEvent (event: keyof QueueEvents<JobReturnType>, filter?: () => boolean): Promise<void> {
Copy link
Member

Choose a reason for hiding this comment

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

Does this need to be abortable?
I guess not if clear/abort will allow all pending promises (from public methods, onEmpty, onSizeLessThan, onIdle, toGenerator) to resolve.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's not abortable in p-queue, though it makes sense

Copy link
Member Author

Choose a reason for hiding this comment

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

They are abortable now

@achingbrain achingbrain merged commit 528d737 into main Jan 6, 2024
22 checks passed
@achingbrain achingbrain deleted the fix/replace-p-queue-with-queue branch January 6, 2024 07:58
@achingbrain achingbrain mentioned this pull request Jan 6, 2024
Comment on lines +79 to +85
"./queue": {
"types": "./dist/src/queue/index.d.ts",
"import": "./dist/src/queue/index.js"
},
"./peer-queue": {
"types": "./dist/src/peer-queue.d.ts",
"import": "./dist/src/peer-queue.js"

Choose a reason for hiding this comment

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

@achingbrain This PR introduces BREAKING CHANGE and actually broke many libp2p projects. Why not to bump major version if you break package API? Libp2p packages use caret ranges and automatically will try to update this package when installed.

This was referenced Jan 18, 2024
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.

3 participants