Skip to content

Instantly share code, notes, and snippets.

@varya
Last active December 2, 2015 14:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save varya/86523922d3e3aceccdf8 to your computer and use it in GitHub Desktop.
Save varya/86523922d3e3aceccdf8 to your computer and use it in GitHub Desktop.
// 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
})
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