# What's an idiomatic way to name a function that takes \`() -\> Unit\` vs \`suspend () -\> Unit\`

**URL:** <https://discuss.kotlinlang.org/t/whats-an-idiomatic-way-to-name-a-function-that-takes-unit-vs-suspend-unit/30809>\
**Category:** Support\
**Created:** [October 27, 2025, 6:16am UTC](https://discuss.kotlinlang.org/t/whats-an-idiomatic-way-to-name-a-function-that-takes-unit-vs-suspend-unit/30809 "2025-10-27T06:16:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bp](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/bp/32/11320_2.png) [@bp](https://discuss.kotlinlang.org/u/bp)\
**Post date:** [October 27, 2025, 6:16am UTC](https://discuss.kotlinlang.org/t/whats-an-idiomatic-way-to-name-a-function-that-takes-unit-vs-suspend-unit/30809/1 "2025-10-27T06:16:03Z")

</div>

I’m trying to get up to speed with Kotlin. One of the things I keep hitting snags with is how functions and `suspend` functions feel like oil and water and don’t mix.

For example if I wanted to wrap some code like this:

```kotlin
time {
  doSomething
}

```

I apparently can’t have it work regardless of whether `doSomething` is `suspend` or not:

```kotlin
package meh;

// I'm not really trying to time code; I'm actually trying to specialize assertFails
// This is just a minimum reproducible program that demonstrates where I'm getting stuck
fun time(fn: () -> Unit) = 0

fun time(fn: suspend () -> Unit) =
  time { /* Overload resolution ambiguity between candidates
          * fun time(fn: () -> Unit): Int
          * fun time(fn: suspend () -> Unit): <ERROR TYPE REF: Ambiguity: time, [meh/time, meh/time]>
          */
    runBlocking {
      fn.invoke()
    }
  }

```

Is this type erasure and thus intractable, or am I just holding the language wrong? What’s the idiomatic way to work around this? do I call one of them something else, like `timeBlocking` or `timeCoroutine` or `timeSuspend` or `blockAndTime` or..? do I simply fail to factor out the `runBlocking` call from every applicable call site?

In case it matters, my team adopted Kotlin version 2.2.

---

<div class="post-metadata">

**Author:** ![kyay10](https://avatars.discourse-cdn.com/v4/letter/k/c57346/32.png) [@kyay10](https://discuss.kotlinlang.org/u/kyay10)\
**Post date:** [October 27, 2025, 9:58am UTC](https://discuss.kotlinlang.org/t/whats-an-idiomatic-way-to-name-a-function-that-takes-unit-vs-suspend-unit/30809/2 "2025-10-27T09:58:05Z")

</div>

Using `runBlocking` in such a way is a bad idea. Instead what you want is `inline` functions. They’re transparent to suspension, meaning that if the caller is suspend, the block will be suspend too, and if not then it won’t be suspend

---

<div class="post-metadata">

**Author:** ![piyush.mor](https://avatars.discourse-cdn.com/v4/letter/p/51bf81/32.png) [@piyush.mor](https://discuss.kotlinlang.org/u/piyush.mor)\
**Post date:** [October 27, 2025, 1:58pm UTC](https://discuss.kotlinlang.org/t/whats-an-idiomatic-way-to-name-a-function-that-takes-unit-vs-suspend-unit/30809/3 "2025-10-27T13:58:35Z")

</div>

can you please give an example for the inline?

---

<div class="post-metadata">

**Author:** ![kyay10](https://avatars.discourse-cdn.com/v4/letter/k/c57346/32.png) [@kyay10](https://discuss.kotlinlang.org/u/kyay10)\
**Post date:** [October 27, 2025, 5:32pm UTC](https://discuss.kotlinlang.org/t/whats-an-idiomatic-way-to-name-a-function-that-takes-unit-vs-suspend-unit/30809/4 "2025-10-27T17:32:59Z")

</div>

Sure:

```auto
inline fun myAssertFails(block: () -> Unit) { 
  try {
    block()
    // error because it didn't fail
  } catch(blah: SomeAssertionType) {
    // failed successfully, 
  }
}
```

---

<div class="post-metadata">

**Author:** ![Landei](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/landei/32/9407_2.png) [@Landei](https://discuss.kotlinlang.org/u/Landei)\
**Post date:** [October 28, 2025, 9:36pm UTC](https://discuss.kotlinlang.org/t/whats-an-idiomatic-way-to-name-a-function-that-takes-unit-vs-suspend-unit/30809/5 "2025-10-28T21:36:33Z")

</div>

Kotlin 2.2.20 allows you (with language version set to 2.3) to use the suspend keyword on the call side to distinguish both versions, see

> **[What's new in Kotlin 2.2.20 | Kotlin](https://kotlinlang.org/docs/whatsnew2220.html#improved-overload-resolution-for-lambdas-with-suspend-function-types)**

Or as video:  
[https://www.youtube.com/watch?v=QWpp5-LlTqA](https://www.youtube.com/watch?v=QWpp5-LlTqA) (at 6:51)
