await-async-flow

1.0.1 • Public • Published

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' ]

Readme

Keywords

Package Sidebar

Install

npm i await-async-flow

Weekly Downloads

0

Version

1.0.1

License

MIT

Unpacked Size

3.96 kB

Total Files

6

Last publish

Collaborators

  • jiayufeng