jdonaldson / promhx

A promise and functional reactive programming library for Haxe
MIT License
145 stars 24 forks source link

Rejected promise and then #44

Closed mcheshkov closed 9 years ago

mcheshkov commented 9 years ago

I expect that if one start a new chain on promise that already received error that error will propagate to that chain, until it meets promise with catchError called, that is AsyncBase with _error handlers.

This

var p = Promise.promise(1);
p.then(function(a){
    trace("then", a);
}).catchError(function(e){
    trace("catchError", e);
});

outputs

then,1

But this

var p = new Promise<Int>();
p.then(function(a){
    trace("then1", a);
}).catchError(function(e){
    trace("catchError1", e);
});
p.reject(2);
p.then(function(a){
    trace("then2", a);
}).catchError(function(e){
    trace("catchError2", e);
});

outputs

catchError1,2

If reject is called after creating of second chain both will catch error.

If one call then on resolved promise immediateLinkUpdate will catch this up and call next.handleResolve There's also isErrored case, but _errored is never updated.

jdonaldson commented 9 years ago

Thanks again, I'll look into it.

jdonaldson commented 9 years ago

Thanks for the heads up. In many cases the errors after the first thrown error were not getting handled appropriately. I added a fix and another test.