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
Select is a selector, like match, but instead of selecting a message based on a value, it selects based on the source, or in other words, based on the order. It waits for all data senders first and then blocks until the first condition message is sent. As soon as that happens, it selects the message from the data sender corresponding to the condition sender that fired and sends the selected message to the receiver.
Unlike match select cannot have default branch because otherwise it would just send infinitely. Also select is the only selector that cannot have a sender connected to its body. All this because it doesn't have a single thing that "kicks" it - it locks on a set of conditions, each of which will kick it.
select {
email: 'an email was sent'
phone: 'a phone call was made'
} -> println
One might think that this logic can be emulated with deferred connections, but that's not true. First, we would have to create several println nodes, as duplicates are not allowed. Second, deferred connections insert locks and thus create latency. Where you have branching and latency, a race condition is possible.
With Multiple Conditions on a Same Branch
Similar to match, select allows the union of multiple conditions on a single branch:
Unlike if, switch, and match, select is only blocked by data senders and receivers, not by all of its condition senders. This is because it does not wait for all conditions to be met; instead, it sends a message as soon as the first condition is met.
One way to think about selectors is that match maps one value onto another, while select maps an event onto a value.
Similar to previous constructs, select can have multiple receivers connected to its body. It is handled like a fan-out, which affects latency as usual.
The text was updated successfully, but these errors were encountered:
Previous parts:
if
- Routers and Selectors. Part 1if
#802switch
- Routers and Selectors. Part 2switch
#804match
- Routers and Selectors. Part 3match
#805Select
Basic
Select is a selector, like match, but instead of selecting a message based on a value, it selects based on the source, or in other words, based on the order. It waits for all data senders first and then blocks until the first condition message is sent. As soon as that happens, it selects the message from the data sender corresponding to the condition sender that fired and sends the selected message to the receiver.
Example
With Multiple Conditions on a Same Branch
Similar to
match
,select
allows the union of multiple conditions on a single branch:Example
One way to think about selectors is that
match
maps one value onto another, whileselect
maps an event onto a value.The text was updated successfully, but these errors were encountered: