title: how to use suspendCoroutine to turn java 7 future into kotlin suspending function
body: <p>What is the best approach to wrap java 7 futures inside a kotlin suspend function? 
  Is there a way to convert a method returning Java 7 futures into a suspending function? </p>
  
  <p>The process is pretty straightforward for arbitrary callbacks or java 8 completablefutures, as illustrated for example here: 
  * <a href="https://github.com/Kotlin/kotlin-coroutines/blob/master/kotlin-coroutines-informal.md#suspending-functions" rel="noreferrer">https://github.com/Kotlin/kotlin-coroutines/blob/master/kotlin-coroutines-informal.md#suspending-functions</a></p>
  
  <p>In these cases, there is a hook that is triggered when the future is done, so it can be used to resume the continuation as soon as the value of the future is ready (or an exception is triggered). </p>
  
  <p>Java 7 futures however don't expose a method that is invoked when the computation is over.</p>
  
  <p>Converting a Java 7 future to a Java 8 completable future is not an option in my codebase. </p>
  
  <p>Of course, i can create a suspend function that calls future.get() but this would be blocking, which breaks the overall purpose of using coroutine suspension. </p>
  
  <p>Another option would be to submit a runnable to a new thread executor, and inside the runnable call future.get() and invoke a callback. This wrapper will make the code looks like "non-blocking" from the consumer point of view, the coroutine can suspend, but under the hood we are still writing blocking code and we are creating a new thread just for the sake of blocking it</p>