title: Completion Handler Android Kotlin
body: <p>I´m sorry if this question has been asked previously, I really couldn´t find anything not even simillar! I´m as well sorry if the question is dumb, I´m an iOS Developer and I´m a bit lost here in Android...</p>
  
  <p>So I´m using Fuel Library(<a href="https://github.com/kittinunf/Fuel" rel="noreferrer">https://github.com/kittinunf/Fuel</a>) to GET JSON data from an API... In Swift there´s something called completion handler that whenever the function finished, it will return it and immediately run the code inside it. This is an example of it in Swift:</p>
  
  <pre><code>func hardProcessingWithString(input: String, completion: (result: String) -&gt; Void) {
      ...
      completion("we finished!")
  }
  </code></pre>
  
  <p>What I need is to do something similar with this following function that I have in Kotlin. </p>
  
  <pre><code>fun recomendationsData() {
  
      Fuel.get("https://rss.itunes.apple.com/api/v1/us/apple-music/hot-tracks/10/explicit.json").response { request, response, result -&gt;
                      println(request)
                      println(response)
                      val (bytes, error) = result
                      if (bytes != null) {
                          val str = String(bytes)
                          val obj = JSONObject(str)
                          val resultsP = obj.getJSONObject("feed")
                          val results = resultsP.getJSONArray("results")
  
                          for (i in 0..(results.length() - 1)) {
                              val o = results.getJSONObject(i)
                              trackName1.add(o.getString("name"))
                              trackArtist1.add(o.getString("artistName"))
                              trackImage1.add(o.getString("artworkUrl100"))
                          }
  
  
                      }
                  }
  }
  </code></pre>
  
  <p>I´ve read about something called "callback" but I really don´t understand how it works, nor how to implement it(The task must be done Asynchronously).</p>
  
  <p>Thank you very much again!</p>
  
  <p>Regards</p>