Skip to content

JYFiaueng/await-async-flow

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published