Last active
November 30, 2015 23:13
-
-
Save mrkmg/abef6a45169c4e9c5d3e 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
var Promise = require("bluebird"); | |
function doSomething() | |
{ | |
return Promise | |
.try(function () | |
{ | |
return task1(); | |
}) | |
.then(function (result) | |
{ | |
return task2(result); | |
}) | |
.catch(function (error) //Best way to only catch task2? | |
{ | |
return processError(error); | |
}) | |
.then(function (result) //Should not run if task1 throws... | |
{ | |
return keepOnGoing(result); | |
}); | |
} |
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 Promise = require("bluebird"); | |
function doSomething() | |
{ | |
return Promise | |
.try(function () | |
{ | |
return task1(); | |
}) | |
.then(function (result) | |
{ | |
return Promise | |
.try(function () | |
{ | |
return task2(result); | |
}) | |
.catch(function (error) | |
{ | |
return processError(error); | |
}) | |
}) | |
.then(function (result) | |
{ | |
return keepOnGoing(result); | |
}); | |
} |
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 Promise = require("bluebird"); | |
function doSomething() | |
{ | |
return Promise | |
.try(function () | |
{ | |
return task1(); | |
}) | |
.catch(function (error) | |
{ | |
error._some_unique_identfier = true; | |
}) | |
.then(function (result) | |
{ | |
return task2(result); | |
}) | |
.catch(function (error) | |
{ | |
if (error._some_unique_identfier) | |
{ | |
throw error; | |
} | |
else | |
{ | |
return processError(error); | |
} | |
}) | |
.then(function (result) | |
{ | |
return keepOnGoing(result); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment