Skip to content

yuguaa/yuguaa-limit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

yuguaa-limit

使用(类似p-limit)

import yLimit from "yuguaa-limit";
const foo = (value: any, delay: any) =>
  new Promise((resolve) => {
    setTimeout(() => resolve(value), delay);
  });

const limit = yLimit(2);
const arr = [
  limit(() => foo("1", 1000)),
  limit(() => foo("2", 5000)),
  limit(() => foo("3", 5000)),
  limit(() => foo("4", 5000)),
  limit(() => foo("5", 1000)),
  limit(() => foo("6", 5000)),
];
const getData = async () => {
  const res = await Promise.all(arr);
};
getData();