bluebird-as

1.0.3 • Public • Published

bluebird-as

A tiny number of helper functions to use with bluebird (other promise libraries not tested) for higher level functions such as sequence etc

Usage

  var Promise = require('bluebird');
 
  var as = require('bluebird-as');
  as.use(Promise);

sequenceOf

Run Promises in strict sequence (without passing the result).

Note: In bluebird 2.x this is also available with .each

javascript:

  var urls = ['http://www.google.de'];
 
  Promise.resolve(urls)
    .then( as.sequenceOf(function(url){
      return scrapeUrlIntoDatabaseOrSo(url);
    }))
    .then(function(){
      doSomethingWithAllResultsCollectedInDatabase();
    });

coffeescript:

  urls = ['http://www.google.de']
 
  Promise.resolve(urls)
    .then as.sequenceOf (url)->
      scrapeUrlIntoDatabaseOrSo(url)
    .then ()->
      doSomethingWithAllResultsCollectedInDatabase()

This is like async.eachSeries

sequenceWithParallelism

Run promises in sequence but with a degree of parallelism.

javascript:

  var urls = ['http://www.google.de'];
 
  Promise.resolve(urls)
    .then( as.sequenceWithParallelism(10,function(url){
      return scrapeUrlIntoDatabaseOrSo(url);
    }))
    .then(function(){
      doSomethingWithAllResultsCollectedInDatabase();
    });

coffeescript:

  urls = ['http://www.google.de']
 
  Promise.resolve(urls)
    .then as.sequenceWithParallelism 10(url)->
      scrapeUrlIntoDatabaseOrSo(url)
    .then ()->
      doSomethingWithAllResultsCollectedInDatabase()

This is like async.eachLimit

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.0.31latest

Version History

VersionDownloads (Last 7 Days)Published
1.0.31
1.0.20
1.0.10
1.0.00
0.0.40
0.0.30
0.0.20
0.0.10

Package Sidebar

Install

npm i bluebird-as

Weekly Downloads

1

Version

1.0.3

License

MIT

Last publish

Collaborators

  • matthiasg