Suspend constructor? %)
# coroutines
g
Suspend constructor? %)
l
Absolutely! Useful for classes that do I/O in their constructor. This is part of the path to zero I/O on UI thread. I'm prototyping it for shared preferences on Android
g
I think this kind of non-trivial constructor stuff is better left to factory methods, which is arguably what your doing with
suspend op fun invoke()
, but I fear you risk turning your code into scala
an explicit method like
load
(or
loadAsync(): AndroidFuture<Prefs>()
) might be a better idea, especially if you want java interop