updateHandler is a closure that executes with the updated prediction after each polling request to the API. It can be passed as a trailing closure. You can use it to provide feedback to the user about the progress of the prediction, or throw CancellationError to stop waiting for the prediction to finish.
let output = try await replicate.run(
"stability-ai/stable-diffusion-3",
["prompt": "a 19th century portrait of a gentleman otter"]
) { prediction in
// Print the prediction status after each update
print(prediction.status)
}
If the prediction is in a terminal state (e.g. succeeded, failed, or canceled), it's returned immediately and the closure is not executed.
updateHandler
is a closure that executes with the updated prediction after each polling request to the API. It can be passed as a trailing closure. You can use it to provide feedback to the user about the progress of the prediction, or throwCancellationError
to stop waiting for the prediction to finish.If the prediction is in a terminal state (e.g.
succeeded
,failed
, orcanceled
), it's returned immediately and the closure is not executed.