Last active
July 14, 2016 10:34
-
-
Save hkurokawa/9889877e7ab6111ec0874fa2863e29fa to your computer and use it in GitHub Desktop.
A sample code to reproduce an issue that the unsubscription thread is sometimes different from the subscription thread.
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
import rx.Observable; | |
import rx.Subscriber; | |
import rx.Subscription; | |
import rx.schedulers.Schedulers; | |
public class UsingResourceSample { | |
public static void main(String[] args) throws InterruptedException { | |
for (int i = 0; i < 10; i++) { | |
Observable.using(() -> { | |
System.out.println("Getting @" + Thread.currentThread()); | |
return null; | |
}, Observable::just, (aVoid) -> System.out.println("Closing @" + Thread.currentThread())) | |
.subscribeOn(Schedulers.io()) | |
.subscribe() | |
.unsubscribe(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment