josdejong / workerpool

Offload tasks to a pool of workers on node.js and in the browser
Apache License 2.0
2.06k stars 147 forks source link

Promise: add .finally() #388

Closed wmertens closed 2 weeks ago

wmertens commented 1 year ago

Fixes #169

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

josdejong commented 1 year ago

Thanks Wout!

Interesting to see that the finally propagates both the result or error, I wasn't aware of that.

Two feedbacks:

joshLong145 commented 5 months ago

@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

wmertens commented 5 months ago

@joshLong145 I added your commit to this branch

josdejong commented 5 months ago

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?
joshLong145 commented 3 weeks ago

@josdejong @wmertens

PR has been updated with

joshLong145 commented 2 weeks ago

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.

josdejong commented 2 weeks ago

Thanks for the updates Josh!