Advertisement
diesieben07

Untitled

Nov 19th, 2020
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 0.80 KB | None | 0 0
  1. @OptIn(FlowPreview::class)
  2. fun sharingStartedAfterSubs(nSubs: Int, completedSubscribers: Flow<Unit>): SharingStarted {
  3.     return object : SharingStarted {
  4.         override fun command(subscriptionCount: StateFlow<Int>): Flow<SharingCommand> {
  5.             val definitelyStartNow = completedSubscribers
  6.                 .drop(nSubs - 1)
  7.                 .take(1)
  8.  
  9.             val fromSubCount = subscriptionCount
  10.                 .onEach { println("sub count $it") }
  11.                 .dropWhile { it < nSubs }
  12.                 .map { SharingCommand.START }
  13.  
  14.             val result = flowOf(fromSubCount, definitelyStartNow.map { SharingCommand.START })
  15.                 .flattenMerge(concurrency = 2)
  16.  
  17.             return result.take(1)
  18.                 .onEach { println("command: $it") }
  19.  
  20.         }
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement