1.0.1 • Published 6 years ago

await-async-flow v1.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

await-async-flow

将 async 库包装为使用 await 使用形式,在此基础上可以使用任何 async 库的方法

npm npm npm

GitHub forks GitHub stars

Installation

npm install await-async-flow

Example

const async = require('await-async-flow');
const sleep = (t) => {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      resolve(Math.random().toFixed(2));
    }, t);
  });
};

const ret = await async.parallel({
  a: async () => {
    return await sleep(1000);
  },
  b: async () => {
    return await sleep(1000);
  }
});

// { a: '0.97', b: '0.94' }

// or

const ret = await async.map([200, 400, 600], async (t) => {
  return await sleep(t);
});

// [ '0.82', '0.45', '0.69' ]