Is it possible to simplify this code?


I have a java interface where each method has a callback:

interface AccountService {
    fun create(account: Account, handler: Handler<AsyncResult<Long>>)
    operator fun get(id: Long, handler: Handler<AsyncResult<Account>>)

Than I want to use this methods as coroutine, I use this code:

suspend fun <T : Any?> await(f: (Handler<AsyncResult<T>>) -> Unit) : T {
    return awaitResult<T> {
await<Account> { accountService.get(1, it) }

Is it possible to call methods in more beautiful way?

// or even
await<Account> accountService.get(1)

I see only one possible solution to create method extension like xyzAwait() and wrap methods with callbacks


I made a proposal about this