Skip to content

Conversation

@valencik
Copy link
Member

I am attempting to clarify the documentation for race after the semantic change in 3.5.0, introduced in #3453

Namely, the following is now incorrect:

If the winner completes with [[Outcome.Canceled]], the race returns the result of the loser, consistent with the first two rules.

Nailing down this language is tricky.
With less rigidity, here's my understanding of the current behaviour:

If winner Succeeded we cancel loser and return winning value!
If winner Errored we cancel loser and raise the error.
If the winner is Canceled, most of the time we are going to get Canceled overall. The exception is if the loser has managed to also complete, at which point, we already have the loser's value, so why not dish it out.
In other words, Loser is always getting canceled, but if completed prior to that cancelation, we'll let it share its results with the world.

I admit I don't really grok the importance of rule 4 here:

If the race is masked and is canceled because both participants canceled, the fiber will block indefinitely.

Is this a detail that users need in this documentation? I honestly don't know

@valencik valencik self-assigned this Nov 21, 2025
/**
* Races the evaluation of two fibers that returns the result of the winner, except in the
* case of cancelation.
* case of cancelation which cancels the whole race.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is ambiguous: "in the case of cancelation" <- what does this mean? If the fiber executing race is canceled? If one or the other side cancels?

* masked and is canceled because both participants canceled, the fiber will block
* indefinitely.
* returning. 3. If the winner completes with [[Outcome.Canceled]], the loser is canceled
* immediately but its outcome is returned if already completed. 4. If the race is masked
Copy link
Contributor

Choose a reason for hiding this comment

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

There is a subtle point here: if the loser is cancelled, its Succeeded result can be returned even if it's yet to happen.

In other words: "the loser is canceled immediately but its outcome is returned if already completed" <- I think this sentence suggests, that if the loser is not yet completed when it's cancelled, then its outcome will not be returned. This is not true.

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