Created
May 25, 2018 03:22
-
-
Save lastday154/5f3db04deaf04999a135269957cee2af to your computer and use it in GitHub Desktop.
if-else flow in promise (bluebird)
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
| (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