Skip to content

Instantly share code, notes, and snippets.

@alanpaivaa
Last active May 19, 2019 16:45
Show Gist options
  • Save alanpaivaa/816718b9626ad1111f0b5df37552afc2 to your computer and use it in GitHub Desktop.
Save alanpaivaa/816718b9626ad1111f0b5df37552afc2 to your computer and use it in GitHub Desktop.
let observable = Observable<Int>.create { observer -> Disposable in
print("Creating observable")
DispatchQueue.global(qos: .background).asyncAfter(deadline: .now() + 1, execute: {
observer.onNext(2)
}
return Disposables.create()
}
let doubleObservable = observable.map { value -> Int in
print("Multiplying by 2")
return value * 2
}
let doubleSharedObservable = doubleObservable.share()
doubleSharedObservable.printNext("Subscription A")
doubleSharedObservable.printNext("Subscription B")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment