await-cycle

1.0.6 • Public • Published

The function within which the cycle is executed is called in the asynchronous block. Accepts an async function that should return a promise. Will be resolve when all transferred functions are resolved. The transferred functions are called parallel!

Install

$ yarn add await-cycle or $ npm i await-cycle

Example Usage

const awaitCycle = require("await-cycle");
const arr = ["a", "b", "c", "d"];
const delay = (item, idx) => {
  return new Promise(resolve =>
    setTimeout(() => {
      console.log(`in item ${item} - ${idx}`);
      resolve();
    }, 500)
  );
};
(async () => {
  await awaitCycle(arr, (item, idx) => delay(item, idx));
  console.log("after!");
})();

Result

  in item a - 0
  in item b - 1
  in item c - 2
  in item d - 3
  after!

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i await-cycle

      Weekly Downloads

      1

      Version

      1.0.6

      License

      ISC

      Unpacked Size

      2.35 kB

      Total Files

      4

      Last publish

      Collaborators

      • mr.scrpt