In roman’s talk at Kotlin conf it is recommended t...
# coroutines
j
In roman’s talk at Kotlin conf it is recommended to define function which are a coroutine as an extension on
CouroutineScope
what if the coroutine is a method inside class? How is this going to behave?
Copy code
class Watcher {
    fun CoroutineScope.watcherStarted() = async {

    }
}
b
That method can only be invoked within the context of a
Watcher
. So one way you can do this:
Copy code
...launch {
    val watcher = Watcher()
    watcher.run {
        watcherStarted() // invokes the CoroutineScope extension from launch
    }
}