Hello, I would like to use coroutines to handle de...
# coroutines
k
Hello, I would like to use coroutines to handle delay and update of text from an EditText via his TextWatcher listener. In fact, if user continue to type something, I would like to cancel current coroutine and fire another one. It would works like timer/handler implementation for this type of case. Thanks in advance for your time and sorry for my crappy english 😅
g
It's possible to do, do you have any particular problem with it?
k
I don't know how properly cancel my job and then reuse my fragment's scope to launch another one.
g
launch coroutine using async/await, cache Job and cancel it when you want
No need to cancel whole scope, only particular coroutine job
k
Oh, ok, I develop the habit to use the job linked to my global scope 😅 Thanks for your time.
g
But in general I'm not sure that your approach is good, probably better would be convert this callback to stream of events using Flow and write operator (if you need something like debounce/delay such operators already a available)
k
I will have to read some documentation so, thanks again.
g
Debounce operator already available in the latest version of kotlinx.coroutines for Flow
But I'm still not sure that you need debounce particular, depends on your case, but in general it better to use Flow as abstraction
This article do not use any coroutine stream abstraction, so I wouldn't recommend to use it
k
I start to read about Flow, it's totally stranger to me
Thanks again for your advices
🙂
g
k
Thanks