Last active
April 8, 2019 12:24
-
-
Save baldraider/00ff8d9c7851ca9cb2726c1dc04d3a7a 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
//In this example the value 'a' is written to the console: | |
fun BehaviorSubjectExample(){ | |
//Need to provide a default value. | |
var subject = new BehaviorSubject<string>("a") | |
subject.Subscribe(println(it)) | |
} | |
//In this example the value 'b' is written to the console, but not 'a'. | |
fun BehaviorSubjectExample2(){ | |
var subject = new BehaviorSubject<string>("a") | |
subject.onNext("b") | |
subject.subscribe(println(it)) | |
} | |
//In this example the values 'b', 'c' & 'd' are all written to the console, but again not 'a' | |
fun BehaviorSubjectExample3(){ | |
var subject = new BehaviorSubject<string>("a") | |
subject.onNext("b") | |
subject.subscribe(println(it)); | |
subject.onNext("c") | |
subject.onNext("d") | |
} | |
//Finally in this example, no values will be published as the sequence has completed. Nothing is written to the console. | |
fun BehaviorSubjectCompletedExample(){ | |
var subject = new BehaviorSubject<string>("a") | |
subject.onNext("b") | |
subject.onNext("c") | |
subject.onCompleted() | |
subject.subscribe(println(it)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment