Package-level declarations

Utilities for Java Flow.

Functions

Link copied to clipboard

Transforms the given reactive Flow Publisher into Flow. Use the buffer operator on the resulting flow to specify the size of the back-pressure. In effect, it specifies the value of the subscription's request. The default buffer capacity for a suspending channel is used by default.

Link copied to clipboard
fun <T : Any> Flow<T>.asPublisher(context: CoroutineContext = EmptyCoroutineContext): Flow.Publisher<T>

Transforms the given flow into a reactive specification compliant Flow Publisher.

Link copied to clipboard
suspend fun <T> Flow.Publisher<T>.awaitFirst(): T

Awaits the first value from the given publisher without blocking the thread and returns the resulting value, or, if the publisher has produced an error, throws the corresponding exception.

Link copied to clipboard
suspend fun <T> Flow.Publisher<T>.awaitFirstOrDefault(default: T): T

Awaits the first value from the given publisher, or returns the default value if none is emitted, without blocking the thread, and returns the resulting value, or, if this publisher has produced an error, throws the corresponding exception.

Link copied to clipboard
suspend fun <T> Flow.Publisher<T>.awaitFirstOrElse(defaultValue: () -> T): T

Awaits the first value from the given publisher, or calls defaultValue to get a value if none is emitted, without blocking the thread, and returns the resulting value, or, if this publisher has produced an error, throws the corresponding exception.

Link copied to clipboard
suspend fun <T> Flow.Publisher<T>.awaitFirstOrNull(): T?

Awaits the first value from the given publisher, or returns null if none is emitted, without blocking the thread, and returns the resulting value, or, if this publisher has produced an error, throws the corresponding exception.

Link copied to clipboard
suspend fun <T> Flow.Publisher<T>.awaitLast(): T

Awaits the last value from the given publisher without blocking the thread and returns the resulting value, or, if this publisher has produced an error, throws the corresponding exception.

Link copied to clipboard
suspend fun <T> Flow.Publisher<T>.awaitSingle(): T

Awaits the single value from the given publisher without blocking the thread and returns the resulting value, or, if this publisher has produced an error, throws the corresponding exception.

Link copied to clipboard
inline suspend fun <T> Flow.Publisher<T>.collect(action: (T) -> Unit)

Subscribes to this Flow Publisher and performs the specified action for each received element.

Link copied to clipboard
fun <T> flowPublish(context: CoroutineContext = EmptyCoroutineContext, block: suspend ProducerScope<T>.() -> Unit): Flow.Publisher<T>

Creates a cold reactive Flow.Publisher that runs a given block in a coroutine.