Skip to main content
Figranium exposes two Server-Sent Events endpoints, and the Swift SDK surfaces both as AsyncThrowingStream<StreamEvent<JSONValue>, Error>. You consume them with for try await, and you cancel them by cancelling the surrounding Task.

Streams

Both take an optional options argument (headers, timeout).

StreamEvent shape

The SDK parses the data: lines as JSON into JSONValue. If parsing fails, data falls back to a .string containing the raw payload, and raw still contains the original text.

Consume execution events

1

Create a client

Initialize the SDK with your API key.
Client.swift
2

Iterate the stream

Use for try await to consume events as they arrive.
Client.swift
Iteration ends when the server closes the connection or when the stream throws an error. Cancelling the surrounding Task aborts the underlying request.

Terminal timeouts

Streams have no default timeout. Pass options: .init(timeout: 60) when you want a hard deadline; the stream raises FigraniumError(code: "REQUEST_ABORTED") when the timer fires:
Client.swift

Cancel a stream

In Swift, cancellation is done by cancelling the Task that owns the loop. The SDK wires continuation.onTermination to task.cancel(), so the underlying network request is aborted immediately.
Client.swift

Watch an execution with polling

executions.watch polls get at a configurable interval and yields Execution only when the status changes. It finishes automatically when the outcome or status is success, error, stopped, crashed, or anti_bot.
Client.swift
Cancelling the consuming Task also cancels the polling loop and any in-flight request.

Selector stream from a headful browser

The selector stream reports element highlights from a headful browser session. Use it to power visual inspectors:
Client.swift
See Browser resource for opening, inspecting, and stopping headful sessions.

Errors

Streams raise FigraniumError in the same conditions as regular requests:
  • REQUEST_ABORTED: the terminal timeout fired, or the consuming Task was cancelled.
  • NETWORK_ERROR: the stream could not reach the server.
See Errors for the full error shape.
For long-running streams, prefer cancelling the consuming Task over a short timeout so you can stop cleanly when your application state changes.