-
-
Save freiksenet/117995096d111d9767f3 to your computer and use it in GitHub Desktop.
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
// 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 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
async function validateSchema() { | |
await doSomeAsyncSTuff() | |
return true; | |
} | |
async function init() { | |
.. | |
} | |
async function getData() { | |
... | |
} | |
await* [validateSchema(), init()]; | |
await getData() |
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 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() { | |
return new Promise(function(sc, er) { | |
// actions to get data | |
sc(); | |
} | |
}).then(function () { | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment