-
-
Save Maartyl/b40a07e6cb265dd9037a8d5745ebc0bd to your computer and use it in GitHub Desktop.
flow operator that adds pausing upstream
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Suppress("DeprecatedCallableAddReplaceWith") | |
@Deprecated("Temporary, to not use it by accident", level = DeprecationLevel.ERROR) | |
@ExperimentalCoroutinesApi | |
fun <T> Flow<T>.pausedWhen(isPaused: StateFlow<Boolean>) = flow { | |
//WRONG! this impl changes context of a safe flow - violates invariant | |
// - would need to be specially, correctly passed through SafeFlow | |
withContext(mergePausing(currentCoroutineContext(), isPaused)) { | |
emitAll(this@pausedWhen) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment