FlowWrapper

class FlowWrapper<T : Any>(flow: Flow<T>)

Wraps a Kotlin Flow for easy consumption from Swift.

Swift cannot directly consume Kotlin Flows. This wrapper provides a callback-based API that Swift can use natively.

// Swift usage:
let wrapper = FlowWrapper(flow: kmpWorker.observe(taskId: "sync"))
wrapper.collect { state in
print("State: \(state)")
}

// Stop collecting:
wrapper.cancel()

Parameters

flow

The Kotlin Flow to wrap.

Constructors

Link copied to clipboard
constructor(flow: Flow<T>)

Properties

Link copied to clipboard

Returns true if the wrapper is actively collecting.

Functions

Link copied to clipboard
fun cancel()

Stops collecting the flow.

Link copied to clipboard
fun collect(onEach: (T) -> Unit, onComplete: () -> Unit? = null, onError: (Throwable) -> Unit? = null)

Starts collecting the flow and calls onEach for every emitted value. Call cancel to stop collecting.