async-await-all
await for all
Last updated 3 years ago by andy*() .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install async-await-all 
SYNC missed versions from official npm registry.

async-await-all

async-await-all is a JavaScript library for asyncMe, awaitMe, await$

asyncMe = async

awaitMe = await

await$  = await Promise.all(promiseArray)

Examples

const { asyncMe, awaitMe, await$ } = require('async-await-all')

const sleep = ms => {
  return new Promise(resolve => {
    setTimeout(() => resolve(ms), ms)
  })
}

const awaitMeExample = asyncMe(function(ms) {
  try {
    console.log('1...', new Date)
    const ret = awaitMe(sleep(ms))
    console.log('2...', new Date)
    return ret
  } catch (e) {
    console.log(e)
  }
})

const awaitAllExample = asyncMe(function(ms) {
  try {
    console.log('3...', new Date)
    const ret = await$([sleep(ms), sleep(ms*2)])
    console.log('4...', new Date)
    return ret
  } catch (e) {
    console.log(e)
  }
})

awaitMeExample(1000)
  .then(console.log)
  .catch(console.error)
  .then(() => {
    awaitAllExample(1000)
      .then(console.log)
      .catch(console.error)
  })

/*

1... 2017-11-02T07:49:13.636Z
2... 2017-11-02T07:49:14.643Z
1000
3... 2017-11-02T07:49:14.644Z
4... 2017-11-02T07:49:16.649Z
[ 1000, 2000 ]

*/


Installation

npm install --save async-await-all

Usage

You can import from async-await-all:

import { asyncMe, awaitMe, await$ } from 'async-await-all'
// or
const { asyncMe, awaitMe, await$ } = require('async-await-all')

// if you see any issue with node-fibers e.g. There is an issue with `node-fibers`
// please refer to https://github.com/laverdet/node-fibers#supported-platforms

Current Tags

  • 1.2.0                                ...           latest (3 years ago)

3 Versions

  • 1.2.0                                ...           3 years ago
  • 1.1.0                                ...           3 years ago
  • 1.0.0                                ...           3 years ago
Maintainers (1)
Downloads
Today 1
This Week 2
This Month 2
Last Day 1
Last Week 0
Last Month 2
Dependencies (1)
Dev Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |