Promises icon indicating copy to clipboard operation
Promises copied to clipboard

.catch() prevents .then() from getting executed

Open cowwoc opened this issue 11 years ago • 0 comments

Given:

function third()
{
    return new Future(function(future)
    {
        console.log("third");
        future.resolve();
    }).then(function()
    {
        console.log("third.then")
    });
}

function second()
{
    return new function()
    {
        console.log("second");
        return third().catch(errorHandler);
    };
}

return new Future(function(future)
{
    console.log("first");
    future.resolve(second());
}).then(function()
{
    console.log("first.then");
});

I am expecting the following output:

first second third third.then first.then

but first.then is missing. If I comment out .catch(errorHandler) I get first.then as expected. It seems that .catch() is blocking .then().

Expected behavior: .catch() should intercept errors thrown by child Futures, but allow control to bubble up to parent Futures on success.

cowwoc avatar Jun 20 '13 02:06 cowwoc