Created
January 18, 2017 22:13
-
-
Save jwkidd3/976f7d03fdb936208989fd74c8a81618 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| final BehaviorSubject<Integer> subject = BehaviorSubject.create(); | |
| subject.subscribe(i -> { | |
| System.out.println("Received " + i + " on " + Thread.currentThread().getId()); | |
| }); | |
| int[] i = {1}; // naughty side-effects for examples only ;) | |
| Runnable r = () -> { | |
| synchronized(i) { | |
| System.out.println("onNext(" + i[0] + ") on " + Thread.currentThread().getId()); | |
| subject.onNext(i[0]++); | |
| } | |
| }; | |
| r.run(); // Execute on main thread | |
| new Thread(r).start(); | |
| new Thread(r).start(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment