LouisCAD / Splitties

A collection of hand-crafted extensions for your Kotlin projects.
https://splitties.louiscad.com
Apache License 2.0
2.53k stars 159 forks source link

Add suspend listeners like those from Anko #235

Closed domyn closed 4 years ago

domyn commented 4 years ago

Hi, it would be great to have suspend listeners like those from Anko (see here) available in e.g. Views Coroutine splittie. Could you add those please?

LouisCAD commented 4 years ago

Hi, these break structured concurrency, which is not a practice I'm encouraging because it can very easily lead to memory, computational or listener leaks (or all of these).

That said, Splitties already has awaitOneClick() extension function for View in the Views Coroutines split, which allows you to integrate click listening neatly in your suspending function, and disable the button once clicked, until your code is ready to handle a newer click (using a loop, or a flow collector for example).

This is a different approach, but I believe it's better that what Anko listeners offered in terms of design and risks involved.