Skip to Content
How-To GuidesGoFire-and-Forget Invocations in Go (`Trigger`)

Fire-and-Forget Invocations in Go (Trigger)

Overview

Method.Trigger(client, in) enqueues an invocation without waiting for its result and returns an InvocationID, or an error if the invocation could not be enqueued (MustTrigger panics instead). Use it for notifications, fan-out, or handing work to a background/worker agent. Unlike a synchronous Call, Trigger does not block — so it is also safe for an agent to message itself (a synchronous self-Call would deadlock, since one instance handles one invocation at a time).

Steps

  1. Import the target agent’s definition package.
  2. Get a client with Agent.Get(id).
  3. Trigger the method: Target.Method.MustTrigger(client, in) — returns immediately.

Example

package impl import ( "myapp/agents/coordinator" "myapp/agents/worker" "github.com/golemcloud/golem/sdks/go/golem" ) type state struct{} var agent = coordinator.Agent.Implement(func(coordinator.ID) *state { return &state{} }) func init() { agent.Handle(coordinator.Start, func(_ *golem.Context[state], in coordinator.StartIn) golem.Unit { // Hand each unit of work to a worker without awaiting the outcome. for _, w := range in.Jobs { c := worker.Agent.Get(worker.ID{Name: w.Worker}) worker.Dispatch.MustTrigger(c, worker.DispatchIn{Job: w.Job}) } return golem.Unit{} }) }

Fanning out is just a loop of Trigger calls — each runs independently on its target agent.

Trigger vs Call

  • Call(c, in) (Out, error) / MustCall(c, in) Out — blocks, returns the result. Use when you need the value. Never self-Call.
  • Trigger(c, in) (InvocationID, error) / MustTrigger(c, in) InvocationID — returns immediately, no result. Use for notifications, fan-out, and self-messaging.
  • CallAsync(c, in) *Future[Out] — start now, await later with Get() or MustGet(). Use when you want the result but not to block yet (see golem-call-another-agent-go).

The returned InvocationID is an opaque handle to the enqueued invocation; you can ignore it for pure fire-and-forget.

Key Constraints

  • Trigger delivers a value-less enqueue: there is no way to read a return value from it. If you need the result, use Call/CallAsync.
  • As with all RPC, Trigger is called on the method descriptor (worker.Dispatch.Trigger(client, in)), and the client comes from the callee’s definition (worker.Agent.Get(id)).
GuideDescription
golem-call-another-agent-goYou need the callee’s result (sync Call / async CallAsync)
golem-recurring-task-goSchedule a future/self invocation at a specific time
golem-add-agent-goDefine the agent being triggered