Last active
August 29, 2015 11:57
-
-
Save CarlLee/66a667775fbd94802173 to your computer and use it in GitHub Desktop.
checking multiple conditions asynchronously
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var bools = {}; | |
function check1(){ | |
// do something | |
bools['check1'] = condition1; | |
finalChek(); | |
} | |
function check2(){ | |
// do other things | |
bool['check2'] = condition2); | |
finalCheck(); | |
} | |
function finalCheck(){ | |
if(bools['check1'] != undefined && bools['check2'] != undefined){ | |
var finalBool = true; | |
for(var attr in bools){ | |
finalBool &= bools[attr]; | |
} | |
if(finalBool){ | |
//all true | |
}else{ | |
//at least one false | |
} | |
} | |
} | |
// start somthing async | |
async_function(check1); | |
async_function(check2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment