workerpool icon indicating copy to clipboard operation
workerpool copied to clipboard

Promise: add .finally()

Open wmertens opened this issue 2 years ago • 4 comments

Fixes #169

Thanks to https://stackoverflow.com/a/53327815/124416

wmertens avatar Apr 24 '23 08:04 wmertens

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 avatar May 04 '23 09:05 josdejong

@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 avatar Apr 09 '24 22:04 joshLong145

@joshLong145 I added your commit to this branch

wmertens avatar Apr 10 '24 07:04 wmertens

Thanks for the update Wout, it has been a while 😅 .

Two remarks:

  1. Can you describe the new .finally() method in the README.md? There is a list with all methods there that can be extended.
  2. I think the unit tests need to be extended a bit: when I remove the .then and .catch from the two tests, the test still succeeds. So, I think the test should check whether the .then and .catch have been trigered before calling done. It is valuable at least to verify the order in which the .then, .catch, and .finally are triggered so these two tests make sense to me.
  3. Similarly, the finally method 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 avatar Apr 11 '24 10:04 josdejong

@josdejong @wmertens

PR has been updated with

  • New finally implementation
  • Method documentation in README
  • Test case additions to Promise.test.js

joshLong145 avatar Aug 22 '24 23:08 joshLong145

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.

joshLong145 avatar Aug 28 '24 20:08 joshLong145

Thanks for the updates Josh!

josdejong avatar Aug 30 '24 14:08 josdejong