Skip to content

Instantly share code, notes, and snippets.

@jasdev
Last active April 10, 2021 21:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasdev/0fb13c397c1203f5880fa903c776928b to your computer and use it in GitHub Desktop.
Save jasdev/0fb13c397c1203f5880fa903c776928b to your computer and use it in GitHub Desktop.
Rx’s handling of `withLatestFrom` completions.
import RxSwift
// **Scenario one**: `withLatestFrom`’s argument finishes first.
let first = PublishSubject<Int>()
let second = PublishSubject<Int>()
let disposeBag = DisposeBag()
first
.withLatestFrom(second)
.debug()
.subscribe()
.disposed(by: disposeBag)
second.onCompleted()
// Outputs (trimmed):
//
// ```
// -> subscribed
// ``
// **Scenario two**: Upstream finishes first.
// …
first.onCompleted()
// Outputs (trimmed):
//
// ```
// -> subscribed
// -> Event completed
// -> isDisposed
// ```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment