Communication
Channels are built-in primitives. All roles can communicate with each other by writing A->B x
, which reads “role A
sends the value x
to role B
”.
Tempo
// send value from `A` to `B`.
let y@B = await A -> B "hello"@A;
// send value from `A` to `B` and `C` to obtain a shared value.
let y@[A,B,C] = await A->[B,C] "hi everyone"@A
Only values with local or shared roles can be communicated. When a value is communicated its roles are expanded to include the receiving roles.
The result is wrapped in an async
type, which allows the recipient(s) to defer waiting for the message to arrive until it is needed.
Tempo
let x: Int@A = 10;
// `A` sends the value to `B` immediately
let y: async Int@B = A->B x;
// `B` can do other things here...
// when `B` needs the value, `await` is used to wait until the value arrives
let z: Int@B = await y;
Last updated on