Skip to content

Instantly share code, notes, and snippets.

@mrkmg
Last active November 30, 2015 23:13
Show Gist options
  • Save mrkmg/abef6a45169c4e9c5d3e to your computer and use it in GitHub Desktop.
Save mrkmg/abef6a45169c4e9c5d3e to your computer and use it in GitHub Desktop.
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);
});
}
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);
});
}
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