Skip to content

Instantly share code, notes, and snippets.

@toshi0383
Created June 28, 2019 06:18
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 toshi0383/eb70edd05a1f05058738b94db0e40d41 to your computer and use it in GitHub Desktop.
Save toshi0383/eb70edd05a1f05058738b94db0e40d41 to your computer and use it in GitHub Desktop.
let hotdogProperty = BehaviorSubject<String>(value: "")
Observable<Int>
.interval(1.0, scheduler: ConcurrentMainScheduler.instance)
.map { "Nice \($0)" }
.startWith("bonapetit!")
.debug("[source]")
.subscribe(onNext: { hotdogProperty.onNext($0) })
func hotdogObservable() -> Observable<String> {
return hotdogProperty.asObservable()
.share()
.flatMap { Observable.just($0) }
.map { $0 }
.share()
}
func hotdogObservable2() -> Observable<String> {
return hotdogObservable()
}
hotdogObservable2().debug("tom eats lunch")
.subscribeOn(ConcurrentDispatchQueueScheduler(qos: .default))
.delaySubscription(0.5, scheduler: ConcurrentMainScheduler.instance)
.observeOn(ConcurrentDispatchQueueScheduler(qos: .default))
.subscribe()
hotdogObservable2().debug("mary eats lunch")
.subscribe()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment