Skip to content

Instantly share code, notes, and snippets.

@lastday154
Created May 25, 2018 03:22
Show Gist options
  • Select an option

  • Save lastday154/cee864f3e183435f086c368ac6de8f9d to your computer and use it in GitHub Desktop.

Select an option

Save lastday154/cee864f3e183435f086c368ac6de8f9d to your computer and use it in GitHub Desktop.
if-else flow in promise (bluebird)
(conditionA
? fs.writeFileAsync(file, jsonData)
: Promise.resolve())
.then(functionA);
var waitFor;
if (conditionA)
waitFor = fs.writeFileAsync(file, jsonData);
else
waitFor = Promise.resolve(undefined); // wait for nothing,
// create fulfilled promise
waitFor.then(function() {
return functionA();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment