Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Так не раотает
- private Observable<Boolean> getLongAction() {
- Callable<Boolean> callable = new Callable<Boolean>() {
- @Override
- public Boolean call() throws Exception {
- for (int i = 0; i < 16; i++) {
- try {
- Thread.sleep(1000);
- } catch (InterruptedException ex) {
- }
- Lgi.p("long act in thread: " + Thread.currentThread().getName() + ", i = " + i);
- }
- return true;
- }
- };
- return Observable.fromCallable(callable)
- .subscribeOn(Schedulers.io())
- .observeOn(AndroidSchedulers.mainThread());
- //Так работает
- private Observable<Boolean> getLongAction2() {
- ObservableOnSubscribe<Boolean> obs = new ObservableOnSubscribe<Boolean>() {
- @Override
- public void subscribe(ObservableEmitter<Boolean> emitter) throws Exception {
- for (int i = 0; i < 16; i++) {
- try {
- Thread.sleep(1000);
- } catch (InterruptedException ex) {
- }
- if (emitter.isDisposed()) {
- return;
- }
- Lgi.p("long act in thread: " + Thread.currentThread().getName() + ", i = " + i);
- }
- emitter.onNext(true);
- }
- };
- return Observable
- .create(obs)
- .subscribeOn(Schedulers.io())
- .observeOn(AndroidSchedulers.mainThread());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement