Created
November 14, 2024 19:00
-
-
Save blakelee/9d9f4f263b0ac7ca6a2760c872b45339 to your computer and use it in GitHub Desktop.
A sample of how to use RxJava to debounce a user typing text while also prioritizing a user pressing enter and cancelling whatever inflight debounce there was prior.
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
| val textSubject = PublishSubject.create<String>() | |
| val enterPressed = PublishSubject.create<String>() | |
| val debouncedInput = textSubject.debounce(500, TimeUnit.MILLISECONDS) | |
| .takeUntil(enterPressed) | |
| .repeat() | |
| val debounce = Observable.merge( | |
| debouncedInput.map { AnnotatedString(it, SpanStyle(Color.Red)) }, | |
| enterPressed.map { AnnotatedString(it, SpanStyle(Color.Blue)) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment