Skip to content

Instantly share code, notes, and snippets.

@mattmook
Created September 8, 2021 06:01
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 mattmook/d313bf3b26444ea8832b1207c2661dd1 to your computer and use it in GitHub Desktop.
Save mattmook/d313bf3b26444ea8832b1207c2661dd1 to your computer and use it in GitHub Desktop.
OrbitMultiplatform-subscribe.kt
fun Flow<*>.subscribe(onEach: (item: Any) -> Unit, onComplete: () -> Unit, onThrow: (error: Throwable) -> Unit): Job =
this.onEach { onEach(it as Any) }
.catch { onThrow(it) }
.onCompletion { onComplete() }
.launchIn(CoroutineScope(Job() + Dispatchers.Main))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment