Created
July 28, 2015 20:01
-
-
Save ZakTaccardi/c1119fe37a8a5f97eea6 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
List<Integer> coolList = new ArrayList<Integer>(); | |
coolList.add(1); | |
coolList.add(2); | |
coolList.add(3); | |
Observable.from(coolList).map(new Func1<Integer, Long>() { | |
@Override | |
public Long call(Integer integer) { | |
//runs on the IO background thread because we specify `Schedulers.io()` | |
return integer * 10000000000L; | |
} | |
}) | |
//this schedulers tells all previous observables to run on the IO scheduler | |
.subscribeOn(Schedulers.io()) | |
//this schedulers tells the subscriber to run on the main thread | |
.observeOn(AndroidSchedulers.mainThread()) | |
.subscribe(new Subscriber<Long>() { | |
//all these methods run on the main thread because of the `AndroidSchedulers.mainThread()` | |
@Override | |
public void onCompleted() { | |
System.out.println("This went perfectly! this is only called once, and cannot be called if onError is called"); | |
} | |
@Override | |
public void onError(Throwable e) { | |
System.out.println("There was an error! this is only called once, and cannot be called if onCompleted is called"); | |
} | |
@Override | |
public void onNext(Long l) { | |
System.out.println("Emitted number: " + l); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment