Skip to main content
This example shows the two-step pattern at the heart of most iii workflows: an HTTP handler accepts a request and publishes an event to the queue, then a queue handler processes that event in the background and persists the result to state.

Worker setup

Every iii worker starts by initialising the SDK and connecting to the engine.

Step 1 — HTTP handler

Registers a function and binds it to an HTTP trigger. Returns immediately after publishing to the queue.

Step 2 — Queue handler

Consumes the event, builds the greeting, and persists it to state.

Connect and run

Every SDK establishes the WebSocket connection when you call registerWorker(). The process stays alive automatically while connected. Call shutdown() when you want to stop the worker.

Test it

Key concepts

  • iii.registerFunction pairs a string ID with an async handler. The ID is referenced by all triggers bound to that function.
  • iii.registerTrigger binds a trigger type + config to a function ID. A function can have multiple triggers.
  • iii.trigger({ function_id, payload, action: TriggerAction.Enqueue({ queue }) }) enqueues work to a named queue. The target function receives the payload as its input.
  • iii.trigger({ function_id: 'state::set', payload: { scope, key, value }, action: TriggerAction.Void() }) persists data to the engine’s key-value store.