C-Sharp-Promise: Finally promise resolves even if chain is rejected
To reproduce, consider the following promise chain:
new Promise().Then(() => {
throw new Exception();
})
.Finally(() => {})
.Then(() => Debug.Print("SUCCESS");
.Catch(ex => Debug.Print("FAILURE");
In version 1.3.0 of this library, I’m seeing SUCCESS and I expect to see FAILURE. It looks like this is because the Finally method resolves the promise it returns in both the Then and Catch handler of the promise it’s chaining to…that’s not right, is it?
If no, I’m happy to fix and submit a PR.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 1
- Comments: 16 (9 by maintainers)
I’ve renamed it “ContinueWith” now. Will be in the next release (probably 3.0)
Hmm yeah I can see how it would be useful. I do still think that because the functionality is different to finally we should think of a different name for them. Maybe “Always” like you suggested?
We use Semver for versioning, and because the change modifies the functionality of an existing method I’d probably consider that a breaking change.
I’m happy to sign the assembly - I’ll create a key now and include the signed version next time I push a version to Nuget.
That makes sense. Awesome, I’ll get it done!
Hey, sorry I didn’t see this response, or else I would have responded sooner. I’m not sure your example is quite right: even though the finally block on the inner try/finally gets called, your catch handler on the outer try/catch will still get called. E.g.
Running this in a C# application will print: FINALLY EXCEPTION
In fact, if it didn’t, finally blocks would be worthless because if you had to worry about finally swallowing an exception, you would just use a catch block and then code after the catch. I think the same behavior should be implemented in the Promise library: the promise returned from finally should be resolved if the chain above it is resolved, or rejected if the chain above it is rejected.