Skip to content

Latest commit

 

History

History
25 lines (22 loc) · 519 Bytes

README.md

File metadata and controls

25 lines (22 loc) · 519 Bytes

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();