Skip to content

Conversation

@coltfred
Copy link
Member

@coltfred coltfred commented Jul 1, 2025

This fixes #44. The test that's commented out is one that I don't believe should pass, but I'm open to discussion on it.

I would really like a more elegant solution, but I didn't find one that didn't result in an entire rewrite of the class besides this. I'm open to pursuing different ideas if we think this doesn't fix it appropriately. Also totally open to additional test cases.

@coltfred coltfred requested a review from a team as a code owner July 1, 2025 22:52
@coltfred coltfred requested review from BobWall23, giarc3 and skeet70 and removed request for a team July 1, 2025 22:52
@leeroy-travis
Copy link
Collaborator

Commit SHA:419801d2031de141302a115ee49c7df3286512ec
No changes to code coverage between the base branch and the head branch

self review

self review

fix removed type
@coltfred coltfred force-pushed the fix-multiple-handleWith branch from 4623fc7 to 3e5a5fa Compare July 1, 2025 23:05
@leeroy-travis
Copy link
Collaborator

Commit SHA:26620d6af0c423cc2ca8015915c97b1cd61e9942
No changes to code coverage between the base branch and the head branch

}
);
} catch (e) {
expect(handleWithCalledTimes).toBe(1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand based on the description, where does this test show that it the handleWith wasn't run? It looks like it shows that it does, and it's not clear if it's from its own rejection or the rejection thrown in the engage.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the test to show that it's the error that came from the Future.reject

Future.ts Outdated
*/
toPromise(): Promise<R> {
return new Promise<R>((resolve: Resolve<R>, reject: Reject<L>) => this.engage(reject, resolve));
return new Promise<R>((resolve: Resolve<R>, reject: Reject<L>) => this.engageAndCatch(reject, resolve));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be engage? A throw from inside a Promise like this should get caught by the promise. Actually why does engageAndCatch exist with the safe flag like this at all? If we want it, can't we have noThrowEngage or engageAndCatch without the safe argument and always do the safe logic? Anywhere you would write engageAndCatch(x, y, false) you can write engage(x, y) instead right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right on both accounts. Fixed and added a test that shows that an error thrown in the future will be caught by the promise if in a chain.

@coltfred coltfred requested a review from skeet70 July 3, 2025 14:32
@leeroy-travis
Copy link
Collaborator

Commit SHA:9564bb9d804936873833f4325fe34d747393029a
No changes to code coverage between the base branch and the head branch

@coltfred coltfred merged commit a32b0b1 into main Jul 3, 2025
1 check passed
@coltfred coltfred deleted the fix-multiple-handleWith branch July 3, 2025 18:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

handleWith causes Future chain to be called twice if engage resolve fails.

4 participants