Skip to content

Instantly share code, notes, and snippets.

@ragdroid
Created December 5, 2016 22:02
Show Gist options
  • Save ragdroid/1f3223a0b9dbd3f5a29780ca31aff4e0 to your computer and use it in GitHub Desktop.
Save ragdroid/1f3223a0b9dbd3f5a29780ca31aff4e0 to your computer and use it in GitHub Desktop.
Order is not maintain if we use flatMap() while performing "Auto-Complete Search" .
//Order is not maintain if we use flatMap() while performing "Auto-Complete Search"
publishSubject
.debounce(300, TimeUnit.MILLISECONDS)
.flatMap(new Function<String, ObservableSource<List<Book>>>() {
@Override
public ObservableSource<List<Book>> apply(String s) throws Exception {
Log.d(TAG, "getting books for " + s);
return dataSource.getBook(s);
}
})
.subscribeOn(provider.io())
.observeOn(provider.ui())
.subscribe(new Consumer<List<Book>>() {
@Override
public void accept(List<Book> books) throws Exception {
onBooksFetched(books);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment