Skip to main content

recv

In a local protocol, a message arriving at the component the statement is written in. The component waits until it arrives.

component Radar;
component CommandPost;

message struct TrackReport {
    track_id: uint32;
}

local protocol Collect in CommandPost {
    recv let latest: TrackReport from Radar;
}

Payloads​

The payload takes one of the following forms, followed by the connection clause and a semicolon.

  • A name receives into a variable already in scope, which is a var whose type is message data.
  • _ discards what arrives, and _: T discards a message of a stated type.
  • any name: T assuming pred binds the message under a stated assumption.
  • let pattern: T binds what arrives for later statements, and takes an assuming too.

The message type is message data: a non-abstract message struct, or a message variant.

component Radar;
component CommandPost;

message struct TrackReport {
    track_id: uint32;
    bearing_deg: float32;
}

message struct Ack {
    track_id: uint32;
}

local protocol Collect in CommandPost {
    var latest: TrackReport = TrackReport { track_id = 0; bearing_deg = 0.0; };

    recv latest from Radar;
    recv _: Ack from Radar;
    recv any report: TrackReport assuming report.bearing_deg >= 0.0 from Radar;
    recv let first: TrackReport from Radar;
    send any Ack to Radar;
}

Assumptions​

An assuming predicate is what the receiver assumes about the message, checked when the message arrives. Its type is bit.

  • A value that violates the assumption is a safety error at that receipt.
  • The assumption is not a filter and not a guard. It does not wait for a value that satisfies it, and it does not discard one that fails: the receive fires either way.
  • Two arms of a listen receiving the same type and differing only in their assuming are therefore indistinguishable, so an assumption cannot direct a choice by value.
  • The assumption is the counterpart of the sender's where.
  • Neither type checking nor evaluation is affected by an assumption.

Errors​

An assuming predicate that is not bit​

component Radar;
component CommandPost;

message struct TrackReport {
    track_id: uint32;
}

local protocol Collect in CommandPost {
    recv any report: TrackReport assuming report.track_id from Radar;   // error: recv-assumption-type
}

Receiving into a variable that has no wire form​

component Radar;
component CommandPost;

local protocol Collect in CommandPost {
    var count: int32 = 0;
    recv count from Radar;   // error: message-data-type
}
  • send — the matching statement at the other end.
  • listen — arms guarded by a recv, where the message decides which one runs.
  • exch — both halves written as one global statement.
  • connection — the from/to/on clause every message statement carries.