Created
February 2, 2018 01:29
-
-
Save chrislconover/ffb73503ac4bda589eebea3e08627152 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import RxSwift | |
var disposeBag: DisposeBag! = DisposeBag() | |
var variable: Variable<[Int]>! | |
= Variable<[Int]>([1, 2, 3]) | |
var variableObserver: Observable! = variable.asObservable() | |
var subject: PublishSubject<[Int]>! = PublishSubject<[Int]>() | |
var observable: Observable<[Int]>! | |
func foo() { | |
print("Subscribing...") | |
observable = variable.asObservable() | |
observable.subscribe( | |
onNext: { next in print("\tonNext: \(next)") }, | |
onError: { error in }, | |
onCompleted: { print("\tCompleted") }, | |
onDisposed: { print("\tDisposed") }) | |
.disposed(by: disposeBag) | |
print("Releaasing observable does not trigger onDisposed") | |
observable = nil | |
// print("Releaasing variable will trigger completed and disposed") | |
// variable = nil | |
print("releasing subscription triggers onDispose") | |
disposeBag = nil | |
print("Returning from foo()") | |
} | |
foo() | |
print("Returned") |
Author
chrislconover
commented
Feb 2, 2018
Subscribing...
onNext: [1, 2, 3]
Releaasing observable does not trigger onDisposed
Releaasing variable will trigger completed and disposed
Completed
Disposed
Returning from foo()
Returned
done2
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment