Skip to content

Instantly share code, notes, and snippets.

@phucnm
Last active June 1, 2018 14:47
Show Gist options
  • Save phucnm/246ad3eed5309a79a031a3273701e728 to your computer and use it in GitHub Desktop.
Save phucnm/246ad3eed5309a79a031a3273701e728 to your computer and use it in GitHub Desktop.
Rx Leak
Observable.combineLatest(observable1.asObservable(), observable2.asObservable())
.subscribe(onNext: { [weak self] (population, state) in
guard let _self = self else { return }
switch state {
case .connectedHost, .connectedParticipant:
if population == 0 {
_self.roomPopulationState = .waiting
} else {
_self.roomPopulationState = .inARoom
}
case .disconnected:
_self.roomPopulationState = .inNoRoom
case .connecting:
_self.roomPopulationState = .joining
}
})
.disposed(by: disposeBag)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment