Skip to content

Instantly share code, notes, and snippets.

@chonamdoo
Forked from SeongUgJung/other publishsubject
Last active August 29, 2015 14:26
Show Gist options
  • Select an option

  • Save chonamdoo/2ec7b9cb59c899dc03b7 to your computer and use it in GitHub Desktop.

Select an option

Save chonamdoo/2ec7b9cb59c899dc03b7 to your computer and use it in GitHub Desktop.
publishsubject + flatmap problem
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)));
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