observeTaskEvents
abstract fun observeTaskEvents(context: Ctx, taskId: String, lastEventId: String? = null): Flow<TaskEvent>
Returns a Flow of events for a specific task.
The flow will automatically handle reconnection and resumption using lastEventId or stored checkpoints. It terminates when a terminal event (COMPLETED, FAILED, CANCELLED) is received.
Return
A stream of TaskEvents.
Parameters
context
Context for the request.
taskId
The ID of the task to observe.
lastEventId
Optional event ID to start observing from (overrides store).
Samples
runBlocking {
client.observeTaskEvents(taskId).collect { event ->
when (event) {
is TaskProgressEvent -> {
println("Progress: ${event.payload["progress"]}%")
}
is TaskCompletedEvent -> {
println("Task finished successfully!")
}
else -> {
println("Other event: $event")
}
}
}
}Content copied to clipboard