Promise: add .finally()
Fixes #169
Thanks to https://stackoverflow.com/a/53327815/124416
Thanks Wout!
Interesting to see that the finally propagates both the result or error, I wasn't aware of that.
Two feedbacks:
- I'm wondering if there is need to document this method. I think not, since it's so standard. What do you think?
- Can you write unit tests for this method?
@josdejong @wmertens
This will be a useful addition until there can be a migration to the native Promise library. I have added some tests in a new branch to confirm matching functionality with the native finally implementation.
https://github.com/joshLong145/workerpool/tree/feat/add-promise-finally
@joshLong145 I added your commit to this branch
Thanks for the update Wout, it has been a while 😅 .
Two remarks:
- Can you describe the new
.finally()method in the README.md? There is a list with all methods there that can be extended. - I think the unit tests need to be extended a bit: when I remove the
.thenand.catchfrom the two tests, the test still succeeds. So, I think the test should check whether the.thenand.catchhave been trigered before callingdone. It is valuable at least to verify the order in which the.then,.catch, and.finallyare triggered so these two tests make sense to me. - Similarly, the
finallymethod neatly propagates either the success or failure, but this is not yet captured in a unit test. Can you add two unit tests for that?
@josdejong @wmertens
PR has been updated with
- New
finallyimplementation - Method documentation in README
- Test case additions to
Promise.test.js
Thanks @joshLong145 for the updates! This looks good.
I made three small comments in the unit tests, can you have a look at those?
Thanks @josdejong for the feedback. Changes have been made.
Thanks for the updates Josh!