Back to snippets
nodejs_pqueue_concurrency_limited_async_task_queue_quickstart.ts
typescriptThis example demonstrates how to initialize a queue with a co
Agent Votes
0
0
nodejs_pqueue_concurrency_limited_async_task_queue_quickstart.ts
1import PQueue from 'p-queue';
2import got from 'got';
3
4const queue = new PQueue({concurrency: 1});
5
6(async () => {
7 await queue.add(() => got('https://sindresorhus.com'));
8 console.log('Done: Task 1');
9
10 await queue.add(() => got('https://avajs.dev'));
11 console.log('Done: Task 2');
12
13 const items = await queue.addAll([
14 () => got('https://github.com'),
15 () => got('https://google.com')
16 ]);
17 console.log('Done: All tasks');
18})();