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
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 Iteration ends when the server closes the connection or when the stream throws an error. Cancelling the surrounding
for try await to consume events as they arrive.Client.swift
Task aborts the underlying request.Terminal timeouts
Streams have no default timeout. Passoptions: .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 theTask 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
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
Errors
Streams raiseFigraniumError in the same conditions as regular requests:
REQUEST_ABORTED: the terminaltimeoutfired, or the consumingTaskwas cancelled.NETWORK_ERROR: the stream could not reach the server.