title: Kotlin coroutines, is there a better way to return this value?
body: <p>Struggling with coroutines, but is there a better way to use/get the value for a long running call out here before passing it onto another network coroutine with the callback? I've seen others but than i can't seem to use the value with the latest droid coroutine release, like I can't seem make this work <a href="https://stackoverflow.com/questions/47055804/kotlin-coroutines-with-returning-value">Kotlin Coroutines with returning value</a> </p>
  
  <pre><code>private suspend fun launchGeneratePayload(): String? { 
      return withContext (Dispatchers.Default) {
          try {
              val payloadString = slowStringGeneration()//Slow
              return@withContext payloadString
          } catch (e: java.lang.Exception) {
              return@withContext null
          }
      }
  }
  </code></pre>
  
  <p>Where the value is ultimately used</p>
  
  <pre><code>public someFunction(callback: CallBack) {      
      val params: JSONObject = JSONObject()
      params.put("param1", "param1Value")
      runBlocking{ //probably should be launch or similar
          val payload = launchGeneratePayload()
          params.put("param2", payload)
          //call network function with params &amp; callback
          //networkCall (
      } 
  }
  </code></pre>
  
  <p>Thanks for any help</p>
  
  <p>edit: I think was actually looking for was just a bit different with</p>
  
  <pre><code>suspend fun launchGeneratePayload(): String? =
      withContext(Dispatchers.Default) {
          try {
              slowStringGeneration() //slow
          } catch (e: java.lang.Exception) {
               null
          }
      }
  }
  </code></pre>
  
  <p>Will add as an answer later incase i'm still off on this/else.</p>