Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce raceOutcomeBoth #3232

Closed

Conversation

armanbilge
Copy link
Member

This allows us to generalize over raceOutcome and race. The motivation for this is to be able to handle the race condition where both fibers succeed, even though the loser is canceled. More on that in a follow-up PR.

If this merges then I think I need to re-do #3226 in terms of raceOutcomeBoth instead.

@armanbilge armanbilge added this to the v3.4.0 milestone Nov 7, 2022
@armanbilge
Copy link
Member Author

Crap, this was a false generalization. raceOutcome and race vary in how they deal with the scenario that the winning fiber completed in cancelation.

  • raceOutcome always cancels the loser, regardless of how the winner completed
  • race joins the loser, if the winner completed in cancelation

I've currently implemented raceOutcomeBoth like race. But then raceOutcome cannot be derived from it (and indeed this is causing the JS tests to hang).

I have to think about this.

@armanbilge armanbilge removed this from the v3.4.0 milestone Nov 8, 2022
/**
* Races the evaluation of two fibers, cancels the loser, and returns the [[Outcome]] of both.
* If the race is canceled before one or both participants complete, then then whichever ones
* are incomplete are canceled.
Copy link
Contributor

Choose a reason for hiding this comment

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

I may be misunderstanding the intention, but this doesn't seem to be true: if one is canceled, and then the race is canceled while trying the join the other, then the other will not be canceled.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, thanks. I think the scaladoc was expressing my intent, I just screwed up the implementation 😅

case Left((oca, f)) =>
val joined =
if (oca.isCanceled)
poll(f.join)
Copy link
Contributor

Choose a reason for hiding this comment

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

See above, if we're canceled here, f will not be canceled.

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, I think this needs an .onCancel(f.cancel). And same below.

case Right((f, ocb)) =>
val joined =
if (ocb.isCanceled)
poll(f.join)
Copy link
Contributor

Choose a reason for hiding this comment

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

As above.

@armanbilge
Copy link
Member Author

@armanbilge armanbilge closed this Feb 22, 2023
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.

2 participants