Yusuf.I
09/26/2022, 6:54 PMLoney Chou
09/27/2022, 1:12 AMon
function is not inline, that lambda is considered as a closure, and because closure is self-contained, it must "capture" stuff in the outer scope, and now that it's not possible to directly modify a local variable in a closure, that local is wrapped into an object with a var member for the closure to "modify".Yusuf.I
09/27/2022, 6:25 AMYusuf.I
09/27/2022, 2:30 PMYusuf.I
09/27/2022, 2:30 PMLoney Chou
09/30/2022, 1:46 AMinline
your on function or rather just ignore itYusuf.I
10/01/2022, 8:25 AMYusuf.I
10/01/2022, 8:25 AMinline fun <reified T : Event> EvenTester.on(
crossinline consumer: suspend Event.(T) -> Unit
): EventListener {
return object : EventListener {
override suspend fun onEvent(event: Event) {
if (event is T) {
event.consumer(event)
}
}
}
.also { this.addEvent(it) }
}
Loney Chou
10/05/2022, 2:09 AMconsumer
is crossinline, anything inside it should be captured to be used in this EventListener
object, so consumer
is effectively closure. You need to ignore that "Captured..." info then. To be honest this is not a big deal.