iex
07/12/2020, 4:59 PMprivate suspend fun myStruct(): MyStruct = MyStruct(1) {
foo()
}
suspend fun foo() {}
private data class MyStruct(
val a: Int,
val callback: (() -> Unit)?
)Adam Powell
07/12/2020, 5:06 PMmyStruct() to be?streetsofboston
07/12/2020, 5:10 PMfoo is a suspend fun. Your callback parameter must be declared suspend as well if passing it foo , or something calling foo, must compile (or make foo a regular non-suspending fun works as well 😀)streetsofboston
07/12/2020, 5:13 PMmyStruct a suspend fun if you are not calling callback from it...)
private fun myStruct(): MyStruct = MyStruct(1) {
foo()
}
suspend fun foo() {}
private data class MyStruct(
val a: Int,
val callback: (suspend () -> Unit)?
)iex
07/12/2020, 5:18 PMModifier 'suspend' is not applicable to 'non-functional type'(on the lambda's
suspend)streetsofboston
07/12/2020, 5:18 PM( in the correct place now.iex
07/12/2020, 5:20 PMiex
07/12/2020, 5:20 PMiex
07/12/2020, 5:21 PMmyStruct() doesn't have to be actually suspended. I was just struggling to make the callback suspended (where I'm calling send on a BroadcastChannel)Daniel
07/13/2020, 8:12 AM