Tell vs Ask
| Pattern | Use case | Response |
|---|---|---|
| Tell | Fire-and-forget | None |
| Ask | Request-response | Future you can await |
Message types (v4)
From v4.0.0, all message-passing APIs acceptany. You can send:
- Plain Go structs (with CBOR serialization when remote)
- Protocol buffer messages (default ProtoSerializer)
- Any type registered with the serializer
Message ordering
Messages between a specific sender-receiver pair are delivered in the order they were sent (FIFO). This follows from the mailbox being a FIFO queue and the single-threaded processing guarantee per actor.Sender context
InReceive, you can access the sender via ctx.Sender(). It returns a *PID or nil (e.g., for scheduled messages
or when the sender is unknown). Use ctx.Sender().Path() when you need the senderβs address for a reply.
ReceiveContext messaging methods
InsideReceive, the ReceiveContext provides these messaging operations:
| Method | Purpose |
|---|---|
Tell(to *PID, message any) | Fire-and-forget. Does not block. |
Ask(to *PID, message any, timeout) | Request-response. Blocks until reply or timeout. |
Response(resp any) | Reply to an Ask. Call exactly once per Ask message. |
Request(to, message, opts...) | Non-blocking Ask; use continuations for the reply. |
PipeTo(to, task, opts...) | Run task asynchronously; deliver result to to. See PipeTo. |
PipeToName(actorName, task, opts...) | Same, target by name. |
Sender() to get the senderβs PID when replying. Use ActorSystem().ActorOf(ctx, name) to resolve an actor by name
before sending.