Advertisement
diesieben07

Untitled

Nov 19th, 2020
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 0.70 KB | None | 0 0
  1. override fun createBackup(info: BasicBackupInfo, data: Flow<ByteBuffer>): Flow<CreateBackupResult> {
  2.     return channelFlow {
  3.         val completedSubscribers = MutableSharedFlow<Unit>()
  4.  
  5.         val shared = data.onCompletion<ByteBuffer?> { emit(null) }
  6.             .shareIn(this, sharingStartedAfterSubs(delegates.size, completedSubscribers))
  7.             .takeWhile { it != null }
  8.             .filterNotNull()
  9.  
  10.         for (delegate in delegates) {
  11.             launch {
  12.                 try {
  13.                     delegate.createBackup(info, shared).collect { send(it) }
  14.                 } finally {
  15.                     completedSubscribers.emit(Unit)
  16.                 }
  17.             }
  18.         }
  19.     }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement