Closed fergiemcdowall closed 3 years ago
👍
If anybody stumbles upon this later, the incantation for those forced to use require
is ->
const queue = new (await import('p-queue')).default({concurrency: 1})
Thanks for the answer @fergiemcdowall, much appreciated!
Just in case if anyone wants to re-use the PQueue
constructor instead of reusing the same long line of an importation:
let PQueue;
(async () => {
PQueue = (await import('p-queue')).default;
})();
//... * anything *
const queue1 = new PQueue({concurrency: 5});
const queue2 = new PQueue({concurrency: 10});
@otanim yes, if you account for the possible race condition when you first assign PQueue
, then thats a nice way to do it 👍
If anybody stumbles upon this later, the incantation for those forced to use
require
is ->const queue = new (await import('p-queue')).default({concurrency: 1})
I got
const queue = new (await import('p-queue')).default({ concurrency: 1 });
^^^^^
SyntaxError: Unexpected reserved word
error for this
That would be because OP used the await INSIDE an Async Closure. Your example appears to use the await AT TOP LEVEL, which doesn't work in any except possibly a beta version of Node.
If you don't know what Top Level, Async, Await and Closure actually mean you have a fair bit of studying to do before you'll be able to use this.
why so trick do this, some babel ts project can't use this package
My node project doesn't let me
import
modules. Is it possible to use p-queue withrequire
? If so, what is the recommended incantation?