Last active
December 2, 2015 14:55
-
-
Save varya/86523922d3e3aceccdf8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// 1) validate the scheme | |
var validateD = Promise.defer(); | |
// code to validate scheme | |
// .. | |
if (schemeIsValid) { | |
validateD.resolve(); | |
} else { | |
validateD.reject(); | |
} | |
// 2 init smth | |
var initD = Promise.defer(); | |
// some actions to init smth | |
// .. | |
initD.resolve(); | |
Promise.all[validateD, initD]).then(function() { | |
// everything is ready, let's do the business | |
}); | |
// get data | |
var getDataD = Promise.defer(); | |
initD.then(function() { | |
// actions to get data | |
getDataD.resolve(); | |
}); | |
getData.then(function() { | |
// Doing smth with Data | |
}) |
This file contains hidden or 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 validate = new Promise(function(sc, er) { | |
// code to validate scheme | |
// .. | |
if (schemeIsValid) { | |
sc(); | |
} else { | |
er(); | |
} | |
}); | |
var init = new Promise(function(sc, er) { | |
// some actions to init smth | |
// .. | |
sc(); | |
}); | |
Promise.all[validate, init]).then(function() { | |
// everything is ready, let's do the business | |
}); | |
init.then(function() { | |
var getData = new Promise(function(sc, er) { | |
// actions to get data | |
sc(); | |
} | |
}); | |
getData.then(function() { | |
// Nope. There is no getData in this scope. | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment