elizarov
01/29/2019, 7:19 AMdoSomething to do:
• If you want to wait until it finishes doing its work you write suspend fun doSomething() = coroutineScope { ... }
• If you want it to return quickly with a side effect of launching new coroutine, you write fun CoroutineScope.doSometing() = launch { ... }.svenjacobs
01/29/2019, 7:35 AMclass EventBus {
fun CoroutineScope.send(...) { ... }
}
// somewhere else
val eventBus = EventBus()
launch {
eventBus.send(...)
}svenjacobs
01/29/2019, 7:36 AMclass EventBus {
fun send(scope: CoroutineScope, ...) { ... }
}svenjacobs
01/29/2019, 7:38 AMEventBus to work?svenjacobs
01/29/2019, 7:42 AMwith() works but not without. Why is that?svenjacobs
01/29/2019, 7:45 AMeventBus. I thought everything after the . is then called in the context of EventBus. So I'm calling the function on the object. I wonder if this should work for extension function of the object, too?svenjacobs
01/29/2019, 7:52 AMCoroutineScope, why shouldn't the compiler be able to do this
eventBus.send(...)
and pass the CoroutineScope as the first function argument during compile time.streetsofboston
01/29/2019, 12:21 PMinContext function below.
class MyClass {
fun printValue(value :Int) {
println("Value ${value.inContext()}")
}
fun Int.inContext(): String {
return (this + 6).toString() + this@MyClass.hashCode().toString()
}
}
fun main() {
MyClass().printValue(4)
}