🚀 Big News:Socket Has Acquired Secure Annex.Learn More →
Socket
Book a DemoSign in
Socket

async-waiter

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

async-waiter

higher-level functions to simplify waiting for multiple concurrent async operations to finish

latest
Source
npmnpm
Version
0.1.1
Version published
Weekly downloads
7
250%
Maintainers
1
Weekly downloads
 
Created
Source

async-waiter

Higher-level functions to simplify waiting for multiple concurrent async operations to finish.

Install

npm install --save async-waiter

Example


waiter = require 'waiter'

# Wait for `doFoo()` and `doBar()` to finish, then call `cb`
doFooAndBar = (cb) ->
  waiter (wait) ->
    doFoo wait()
    doBar wait()
  , cb

# Wait for all update() operations to finish
updateUsers = (user_ids, data, cb) ->
  waiter (wait) ->
    user_ids.forEach (user_id) ->
      User.update user_id, data, wait()
  , cb

# The wait() function can delegate to a provided callback,
# and the `this` context can be used to pass data to the callback
loadUserWithFriends = (user_id, cb) ->
  waiter (wait) ->
    User.loadUser user_id, wait (user) -> @data = user.data
    User.loadFriends user_id, wait (@friends) ->
  , (err, ctx) ->
    if err? then cb err
    else cb null, ctx.data, ctx.friends

License

MIT

Keywords

async

FAQs

Package last updated on 08 Dec 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts