Skip to content

Instantly share code, notes, and snippets.

@Fi5t
Created October 17, 2015 18:26
Show Gist options
  • Save Fi5t/7fb2a2c9f0e96cc13b18 to your computer and use it in GitHub Desktop.
Save Fi5t/7fb2a2c9f0e96cc13b18 to your computer and use it in GitHub Desktop.
final Scheduler scheduler = Schedulers.from(Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()));
Observable.just("1", "2", "3", "4", "5")
.flatMap(id -> loadFileById(scheduler, id))
.observeOn(AndroidSchedulers.mainThread())
.subscribe(s2 -> hello.setText(hello.getText() + "\n" + s2));
private Observable<String> loadFileById(final Scheduler scheduler, final String id) {
return Observable.defer(
() -> Observable.just(id)
.map(s -> "<" + Thread.currentThread().getName() + ">" + s) // <- put loading method here
).subscribeOn(scheduler);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment