cancellable

fun <T> Flow<T>.cancellable(): Flow<T> (source)

Returns a flow which checks cancellation status on each emission and throws the corresponding cancellation cause if flow collector was cancelled. Note that flow builder is cancellable by default.

This operator provides a shortcut for .onEach { currentCoroutineContext().ensureActive() }. See ensureActive for details.