https://kotlinlang.org logo
Title
g

gildor

04/13/2018, 9:48 AM
Suspend constructor? %)
l

louiscad

04/13/2018, 9:58 AM
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

groostav

04/14/2018, 4:17 PM
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