# Is it possible to simplify this code?

**URL:** <https://discuss.kotlinlang.org/t/is-it-possible-to-simplify-this-code/8555>\
**Category:** Language Design\
**Created:** [July 13, 2018, 2:27pm UTC](https://discuss.kotlinlang.org/t/is-it-possible-to-simplify-this-code/8555 "2018-07-13T14:27:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mystdeim](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/mystdeim/32/5330_2.png) [@mystdeim](https://discuss.kotlinlang.org/u/mystdeim)\
**Post date:** [July 13, 2018, 2:27pm UTC](https://discuss.kotlinlang.org/t/is-it-possible-to-simplify-this-code/8555/1 "2018-07-13T14:27:03Z")

</div>

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> {
        f(it)
    }
}
await<Account> { accountService.get(1, it) }

```

Is it possible to call methods in more beautiful way?

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

```

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

---

<div class="post-metadata">

**Author:** ![fvasco](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/fvasco/32/1961_2.png) [@fvasco](https://discuss.kotlinlang.org/u/fvasco)\
**Post date:** [July 13, 2018, 2:59pm UTC](https://discuss.kotlinlang.org/t/is-it-possible-to-simplify-this-code/8555/2 "2018-07-13T14:59:46Z")

</div>

I made a proposal about this

> [@@Suspend Java annotations for Kotlin coroutine sugar](https://discuss.kotlinlang.org/t/suspend-java-annotations-for-kotlin-coroutine-sugar/8077):
>
> This in an extension of proposal 111, discussion here [Java annotations for Kotlin sugar · Issue #110 · Kotlin/KEEP · GitHub](https://github.com/Kotlin/KEEP/issues/110) The goal is to enhance the integration between Kotlin and Java CPS methods. Annotations This proposal requires two new annotations: Suspend and ContinuationAdapter. @Target(AnnotationTarget.FUNCTION) @Retention(AnnotationRetention.BINARY) annotation class Suspend() @Target(AnnotationTarget.TYPE, AnnotationTarget.FUNCTION) @Retention(AnnotationRetention.BINARY) annotati…
