Skip to content

Instantly share code, notes, and snippets.

@hoc081098
Created March 24, 2022 18:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hoc081098/3e0d6bbf7eaddd26348108e9edf226f4 to your computer and use it in GitHub Desktop.
Save hoc081098/3e0d6bbf7eaddd26348108e9edf226f4 to your computer and use it in GitHub Desktop.
@ExperimentalCoroutinesApi
public fun <T> race(flow1: Flow<T>, flow2: Flow<T>, vararg flows: Flow<T>): Flow<T> =
race(
buildList(capacity = 2 + flows.size) {
add(flow1)
add(flow2)
addAll(flows)
}
)
@ExperimentalCoroutinesApi
public fun <T> Flow<T>.raceWith(flow: Flow<T>, vararg flows: Flow<T>): Flow<T> = race(
buildList(capacity = 2 + flows.size) {
add(this@raceWith)
add(flow)
addAll(flows)
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment