title: In Kotlin, is it possible to substitute a suspend fun with a non-suspend version, without breaking the caller?
body: <p>I'm learning concurrency in Kotlin, coming from C#/JavaScript background, and I can't help comparing some concepts.</p>
  <p>In C# and JavaScript, technically we can rewrite an <code>async</code> function as a regular non-async version doing the same thing, using <code>Task.ContinueWith</code> or <code>Promise.then</code> etc.</p>
  <p>The caller of the function wouldn't even notice the difference (I ranted about it in a <a href="https://dev.to/noseratio/yet-another-async-await-question-for-javascript-interviews-1hon" rel="nofollow noreferrer">blog post</a>).</p>
  <p>Is something like that possible for a <code>suspend</code> function in Kotlin (i.e., without changing the calling code)? I don't think it is, but I thought I'd still ask.</p>
  <p>The closest thing I could come up with is below (<a href="https://pl.kotl.in/_AmzanwcB" rel="nofollow noreferrer">Kotlin playground link</a>), I still have to call <code>.await()</code>:</p>
  <pre class="lang-kotlin prettyprint-override"><code>import kotlinx.coroutines.*
  
  suspend fun suspendableDelay(ms: Long): Long {
      delay(ms);
      return ms;
  }
  
  fun regularDelay(ms: Long): Deferred&lt;Long&gt; {
      val d = CompletableDeferred&lt;Long&gt;()
      GlobalScope.async { delay(ms); d.complete(ms) }
      return d;
  }
  
  suspend fun test(ms: Long): Long {
      delay(ms);
      return ms;
  }
  
  fun main() {
      val r1 = runBlocking { suspendableDelay(250) }
      println(&quot;suspendableDelay ended: $r1&quot;);
      val r2 = runBlocking { regularDelay(500).await() }
      println(&quot;regularDelay ended: $r2&quot;);
  }
  </code></pre>
  <p><a href="https://pl.kotl.in/_AmzanwcB" rel="nofollow noreferrer">https://pl.kotl.in/_AmzanwcB</a></p>