https://kotlinlang.org logo
Title
u

ursus

12/03/2019, 5:33 AM
root suspend call needs to be within launch, why is it messy?
j

Joey

12/03/2019, 5:41 AM
I have a start and stop button. The functions attached to the two button are both suspend function from my custom library. So im calling them like
setOnclickListener { launch { startFunction() }}
Its messy because i kinda keep on calling them inside
launch {}
u

ursus

12/03/2019, 5:57 AM
launch gives you scope, its similar to disposables in rx, every subscribe everywhere you need to keep the disposable and then clear it
g

gildor

12/08/2019, 8:30 AM
It's indeed suboptimal to work with listeners like that, just launch new operation. It may be fine if you have a couple cases, but very soon becomes very tedious and error prone. Much better to use an adapter that converts listeners to Flow. There is some community library for that (inspired by RxBindings), but didn't try it