Day159 — Kotlin tips
1 min readJan 4
--
- convert callback to coroutine to avoid callback hell using suspendCoroutine
callback:
suspendCoroutine:
note that suspendCoroutine
does not change the CoroutineContext
. It simply converts callback to suspend function which is more manageable.
2. out
declaration-site variance: you can annotate the type parameter
T
ofSource
to make sure that it is only returned (produced) from members ofSource<T>
, and never consumed.
https://kotlinlang.org/docs/generics.html#declaration-site-variance
3. inline function
https://www.baeldung.com/kotlin/inline-functions#inline-functions
When using inline functions, there is no extra object allocation and no extra virtual method calls.