Open jonsmirl opened 1 year ago
Does this work? It is from the Kotlin documentation.
inline suspend fun <T> vx(crossinline callback: (Handler<AsyncResult<T>>) -> Unit) =
suspendCoroutine<T> { cont ->
callback(Handler { result: AsyncResult<T> ->
if (result.succeeded()) {
cont.resume(result.result())
} else {
cont.resumeWithException(result.cause())
}
})
}
Using this helper function, an arbitrary asynchronous vert.x function async.foo(params, handler) can be invoked from a coroutine with vx { async.foo(params, it) }.
It should be possible in Kotlin to template all of this and just pass in the command: getAdministratorCommissioningClusterForDevice. From the command the template should be able to extract the parent class and the parameters. I'm sure a Google Kotlin expert can write this even more efficiently that I can think of. Then you'd just list the commands you need and the templates would expand everything.