Last active
April 22, 2024 18:10
-
-
Save matthewrkula/7700752b19e4cc547bd13edac5089869 to your computer and use it in GitHub Desktop.
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
object CancellableScope | |
interface CancellableUseCase { | |
context(CancellableScope) | |
suspend operator fun invoke(): Result | |
} | |
suspend fun <T> Flow<T>.collectLatestSafe(action: suspend context(CancellableScope) (value: T) -> Unit) { | |
collectLatest { item -> | |
with(CancellableScope) { | |
action(this, item) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment