You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

r3b-promise

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

r3b-promise

A minimal promise implementation

0.0.1
latest
Source
npmnpm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

promise

A very minimal Promise implementation. Creates a simple deferred object with utility methods for sequential or parallel execution. that's it.

var Promise= require('r3b-promise');

function asyncTask(options, callback){
  //do something
  callback();
}

function postProcessingTask(err, result){
  //process
}

function process(options){
  var p = new Promise();
  asyncTask(options, function(err, result){
    p.done(err, result);
  }
  return p;
}

function run(){
  process({}).then(postProcessingTask);
}

function runInParallel(){
  Promise.join([
    asyncTask({property:'value1'}),
    asyncTask({property:'value2'}),
    asyncTask({property:'value3'}),
  ]).then(function(errors, results){
    errors.forEach(function(err){
      //handle error
    });
    results.forEach(function(result){
      //handle result
    });
  });
}

function step(err, data){
  var p = new Promise();
  passItOn(function(err, result){
    p.done(err, result);
  }
  return p;
}
function runInSequence(){
  Promise.chain([
    step({property:'value1'}),
    step({property:'value2'}),
    step({property:'value3'}),
  ]);
}

Keywords

promise

FAQs

Package last updated on 02 Apr 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