-
-
Save chonamdoo/2ec7b9cb59c899dc03b7 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())); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment