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

p-queue hanging #163

Open
leosbotelho opened this issue Jun 24, 2022 · 2 comments
Open

p-queue hanging #163

leosbotelho opened this issue Jun 24, 2022 · 2 comments

Comments

@leosbotelho
Copy link

leosbotelho commented Jun 24, 2022

[WTF Node?] open handles:
- Timers:
  - (58570 ~ 58 s) (anonymous) @ file:///.../node_modules/p-queue/dist/index.js:283
- Intervals:
  - (60000 ~ 60 s) (anonymous) @ file:///.../node_modules/p-queue/dist/index.js:322

dist/index.js:283
dist/index.js:322

First it hangs on dist/index.js:283; and then, if you let it run for a while, on dist/index.js:322 as well.

My code is analogous to:

(async () => {
  for (let i = 0;i < 4;i++) {
    await Q.add(() => sth())  
  }
  // await Q.onIdle()
  // console.log("this is reached (ofc)")
})()

say

// initialized outside the async arrow (lexical scope)
// also hangs when this is
//  initialized inside the async arrow ('async context')
const Q = new PQueue({
  concurrency: 100,
  intervalCap: 500,
  interval: 60 * 1000
})
$ nvm current
v16.15.0

$ lsb_release -d
Description:	Pop!_OS 20.04 LTS

re
sindresorhus/p-throttle#6 (comment)

@leosbotelho
Copy link
Author

leosbotelho commented Jun 25, 2022

This seems more dependable, in the foreseeable future:

import pLimit from "p-limit"
import pThrottle from "p-throttle"

// no feature parity
export default ({ concurrency, intervalCap, interval }) => {
  const limit = pLimit(concurrency)
  const throttle = pThrottle({
    limit: intervalCap,
    interval
  })
  return {
    add: th => throttle(() => limit(th))()
  }
}

@dmgawel
Copy link

dmgawel commented May 24, 2023

I experienced the same issue when using larger interval, say 1 minute (interval: 60000). The whole program seem to hang for that minute.

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

No branches or pull requests

2 participants