sindresorhus / p-limit

Run multiple promise-returning & async functions with limited concurrency
MIT License
2.06k stars 106 forks source link

Function sometimes run synchronously, sometimes asynchronously #22

Closed dcporter closed 4 years ago

dcporter commented 4 years ago

If you pass in a function to a Limit, if there's space in the queue it runs the function synchronously. If there isn't, of course it runs later. This makes the performance characteristics of enqueuing unpredictable, and results in state sometimes changing before the next line of code, and sometimes not. (My team affectionately refers to the set of subtle bugs that this "sometimes-sync-sometimes-async" behavior can call as "zalgo".) It would be nice if enquing always deferred the enqueued function at least until the next tick.

sindresorhus commented 4 years ago

This is a bug and not intended behavior.

qhxin commented 4 years ago

yes, and, it may cause the queue not be finished.

sjgmojica commented 4 years ago

This issue Is solve? Thanks