Skip to content

Instantly share code, notes, and snippets.

@CarlLee
Last active August 29, 2015 12:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CarlLee/9fb961270a4f50dd3eee to your computer and use it in GitHub Desktop.
Save CarlLee/9fb961270a4f50dd3eee to your computer and use it in GitHub Desktop.
async_conditioning with [async module](https://github.com/caolan/async)
var async = require('async');
var bools = {};
function check1(){
// do something
bools['check1'] = condition1;
}
function check2(){
// do other things
bools['check2'] = condition2;
}
async.parallel([check1, check2], function(err, results){
var finalBool = true;
for(var attr in bools){
finalBool &= bools[attr];
}
if(finalBool){
//all true
}else{
//at least one false
}
});
var async = require('async');
function check1(callback){
// do something
callback(null, condition1);
}
function check2(callback){
// do other things
callback(null, condition2);
}
async.parallel([check1, check2], function(err, results){
// results is always in the order of [condition1, condition2] no matter check1 or check2 finishes first
var finalBool = true;
results.forEach(function(result){
finalBool &= result;
});
if(finalBool){
//all true
}else{
//at least one false
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment