Created
July 27, 2022 03:40
-
-
Save devrath/115e276d42b0fc3254bd8070760d99f7 to your computer and use it in GitHub Desktop.
CallbackFlow builder
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
| // https://medium.com/swlh/callback-flows-in-android-d2c6ed5bc488 | |
| fun TextView.textWatcherFlow(): Flow<CharSequence?> = callbackFlow<CharSequence?> { | |
| val textWatcher = object: TextWatcher { | |
| override fun afterTextChanged(s: Editable?) { | |
| sendBlocking(s) | |
| } | |
| // Other callback mehthods | |
| } | |
| addTextChangedListener(textWatcher) | |
| awaitClose { removeTextChangedListener(textWatcher) } | |
| }.buffer(Channel.CONFLATED) | |
| .debounce(300L) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment