Day159 — Kotlin tips

Jacky Tsang
1 min readJan 4


  1. convert callback to coroutine to avoid callback hell using 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 of Source to make sure that it is only returned (produced) from members of Source<T>, and never consumed.

3. inline function

When using inline functions, there is no extra object allocation and no extra virtual method calls.