Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @OptIn(FlowPreview::class)
- fun sharingStartedAfterSubs(nSubs: Int, completedSubscribers: Flow<Unit>): SharingStarted {
- return object : SharingStarted {
- override fun command(subscriptionCount: StateFlow<Int>): Flow<SharingCommand> {
- val definitelyStartNow = completedSubscribers
- .drop(nSubs - 1)
- .take(1)
- val fromSubCount = subscriptionCount
- .onEach { println("sub count $it") }
- .dropWhile { it < nSubs }
- .map { SharingCommand.START }
- val result = flowOf(fromSubCount, definitelyStartNow.map { SharingCommand.START })
- .flattenMerge(concurrency = 2)
- return result.take(1)
- .onEach { println("command: $it") }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement