Last active
August 29, 2015 14:26
-
-
Save SeongUgJung/c653d482f1d36c373cc8 to your computer and use it in GitHub Desktop.
publishsubject + flatmap problem
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
List<ChatChooseItem> chatChooseItems = getMockItems(); | |
List<ChatChooseItem> testList = new ArrayList<>(); | |
PublishSubject<String> publishSubject = PublishSubject.create(); | |
publishSubject | |
.throttleWithTimeout(300, TimeUnit.MILLISECONDS) | |
.flatMap(s -> Observable.from(chatChooseItems) | |
.filter(chatChooseItem -> chatChooseItem.getName().toLowerCase().contains(s.toLowerCase())) | |
.toSortedList((lhs, rhs) -> lhs.getName().toLowerCase().compareTo(rhs.getName().toLowerCase())) | |
) | |
.subscribe(testList::addAll); | |
publishSubject.onNext("he"); | |
Awaitility.await().until(() -> testList.size() > 0); | |
MatcherAssert.assertThat(testList.size(), CoreMatchers.is(IsEqual.equalTo(2))); |
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
List<ChatChooseItem> chatChooseItems = getMockItems(); | |
List<ChatChooseItem> testList = new ArrayList<>(); | |
PublishSubject<String> publishSubject = PublishSubject.create(); | |
publishSubject | |
.throttleWithTimeout(300, TimeUnit.MILLISECONDS) | |
.flatMap(s -> Observable.from(chatChooseItems) | |
.filter(chatChooseItem -> chatChooseItem.getName().toLowerCase() | |
.contains(s.toLowerCase()))) | |
.toSortedList((lhs, rhs) -> lhs.getName().toLowerCase().compareTo(rhs.getName().toLowerCase())) | |
.subscribe(testList::addAll); | |
publishSubject.onNext("he"); | |
Awaitility.await().until(() -> testList.size() > 0); | |
MatcherAssert.assertThat(testList.size(), CoreMatchers.is(IsNull.notNullValue())); |
I think toSortedList
of PublishSubject need to onComplete.
so If you combine with flatMap & sort, then toSortedList
is in flatMap
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
it would be assertion fail.