Skip to content

Instantly share code, notes, and snippets.

@freiksenet
Forked from varya/with Defer
Last active December 2, 2015 14:58
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 freiksenet/117995096d111d9767f3 to your computer and use it in GitHub Desktop.
Save freiksenet/117995096d111d9767f3 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
})
async function validateSchema() {
await doSomeAsyncSTuff()
return true;
}
async function init() {
..
}
async function getData() {
...
}
await* [validateSchema(), init()];
await getData()
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