Skip to main content
A grain processes one message at a time, so blocking on slow I/O inside 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

All three are methods on GrainContext, so they are called from inside OnReceive.

Task signature and outcome

  • Success: the any result is delivered to the target as a normal message.
  • Failure with a grain target (PipeToSelf, PipeToGrain): the target receives a *StatusFailure message carrying the error; handle it in OnReceive via msg.Error(). A WithTimeout expiry counts as a failure.
  • Failure with an actor target (PipeToActor): the error follows the actor PipeTo semantics and goes to the dead-letter queue.
Delivery to a grain target uses the regular grain addressing path: if the target has passivated by the time the task completes, delivery reactivates it. The task itself is detached from the current message’s context, so it keeps running after the originating call completes.
The task runs outside the grain’s single-threaded message loop. Never read or mutate grain state inside it; hand results back through the piped message and update state when it arrives in OnReceive.

Options

Only one of the two may be used per call; using both returns ErrOnlyOneOptionAllowed.

Example

The grain stays responsive while 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