You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Race is a router like if and switch. But like select it makes decisions based on message arrival order rather than message values. First it receives a message to route from data_sender, then it wait for the first condition sender to trigger and sends data message to selected reciver.
Unlike select race can include a default branch that receives messages when no condition sender has fired. This is because unlike select it does have a special inport that kicks it - without message from data-sender, there's nothing to route.
The message final receiver receive is of type RaceResult<T>
{
data T // data message
idx int // 0-based index of the branch that was selected
}
Selector
Race, like other routers, has a selector-mode where it can choose both the message to send and the direction to send it. When used this way, its body must not be connected to a single data-sender, because all the data-senders are inside:
In that case it also receives a RaceResult with the selected data message and index of the selected branch.
Multiple Conditions and Receivers
Race supports multiple condition senders per branch and multiple receivers per branch. Multiple condition senders are treated as "one of" (first to fire wins), while multiple receivers create a fan-out pattern.
Previous parts:
if
- Routers and Selectors. Part 1if
#802switch
- Routers and Selectors. Part 2switch
#804match
- Routers and Selectors. Part 3match
#805select
- Routers and Selectors. Part 4select
#806Race
Basic
Race is a router like
if
andswitch
. But likeselect
it makes decisions based on message arrival order rather than message values. First it receives a message to route from data_sender, then it wait for the first condition sender to trigger and sends data message to selected reciver.With Default Branch (Non-Blocking)
Unlike
select
race can include a default branch that receives messages when no condition sender has fired. This is because unlike select it does have a special inport that kicks it - without message from data-sender, there's nothing to route.With Final Receiver
Like other routers, Race can have a final receiver. It receives a data message after selected branch receiver has received it
The message final receiver receive is of type
RaceResult<T>
Selector
Race, like other routers, has a selector-mode where it can choose both the message to send and the direction to send it. When used this way, its body must not be connected to a single data-sender, because all the data-senders are inside:
This form can also include a final receiver, which receives the selected data message:
In that case it also receives a
RaceResult
with the selected data message and index of the selected branch.Multiple Conditions and Receivers
Race supports multiple condition senders per branch and multiple receivers per branch. Multiple condition senders are treated as "one of" (first to fire wins), while multiple receivers create a fan-out pattern.
As a Conditional Lock
Race covers simple pattern where there's only one direction to send, but several conditions to lock/unlock:
The text was updated successfully, but these errors were encountered: