Skip to content

uknowzheng/PromiseQuene

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PromiseQuene

Summary

Provide a current-limiting Promise queue for solving multiple Promise concurrency.

Main scene:

  • Large file downloads need to control the number of concurrent download tasks

How to use?

install by npm:

npm i promise-quene

example:

const PromiseQuene = require('promise-quene');
const pq = new PromiseQuene({
  concurrency:3 // you can set the max concurrency number
});

[1,2,3,4,5].forEach((v)=>{
  pq.add(()=>new Promise((resolve)=>{
    // you can do something async
    setTimeout(()=>{
      console.log(v);
      resolve("result");
    },1000);
  }).then(result => {
     // if you want to handle the result,just use fetch() api
     console.log(result);
  }))
});