Last active
January 30, 2025 08:29
-
-
Save itsusmon/960c3764834dcf2244852f8af83d205f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* Inspired by Jaewoong Eum's flow-operators library (https://github.com/skydoves/flow-operators). | |
*/ | |
class Restartable { | |
private val restartFlow = MutableSharedFlow<SharingCommand>(extraBufferCapacity = 2) | |
fun restart() { | |
restartFlow.tryEmit(SharingCommand.STOP_AND_RESET_REPLAY_CACHE) | |
restartFlow.tryEmit(SharingCommand.START) | |
} | |
companion object { | |
@JvmStatic | |
fun SharingStarted.with(restartable: Restartable) = SharingStarted { subscriptionCount -> | |
merge(restartable.restartFlow, command(subscriptionCount)) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment