OnReceive stalls every queued message. The
pipe methods offload that work: the task runs in a goroutine outside the message loop, the grain keeps processing, and
the outcome comes back as an ordinary message.
API
- PipeToSelf: delivers the result to this grain.
- PipeToGrain: delivers the result to another grain.
- PipeToActor: delivers the result to a named actor.
GrainContext, so they are called from inside OnReceive.
Task signature and outcome
Task signature and outcome
- Success: the
anyresult is delivered to the target as a normal message. - Failure with a grain target (
PipeToSelf,PipeToGrain): the target receives a*StatusFailuremessage carrying the error; handle it inOnReceiveviamsg.Error(). AWithTimeoutexpiry counts as a failure. - Failure with an actor target (
PipeToActor): the error follows the actor PipeTo semantics and goes to the dead-letter queue.
Options
- WithTimeout: Abort delivery if the task does not complete within
d. - WithCircuitBreaker: If the circuit breaker is open, do not deliver; drop the outcome.
ErrOnlyOneOptionAllowed.
Example
Example
fetchReportData runs; the report data (or a *StatusFailure on error or timeout)
arrives as a later message and is serialized with the grain’s other traffic.
See also
- Grains: lifecycle, identity, and messaging
- PipeTo: the actor-side API and shared option details
- Grain Reentrancy: non-blocking requests to other grains and actors