title: For loop in thread on JSONArray iterates only once and I do not know why
body: <p>I have for loop in Runnable class and it gets data from listener from other runnable but this other runnable is on the same thread that the first runnable (its just call .run() method to reuse some code and everything works fine up untill now... I'm getting JSONObject that contains 2 importand variables, one of them is JSONArray that i'm saving as &quot;tempResult&quot;, it's 14 objects long and the said object is never null. Then when I'm trying to iterate through it it stops after I'm trying to add the extracted object &quot;Vod&quot; to ArrayList. Here is the code of interesting part...</p>
  <pre><code>if (result!!.get(&quot;data&quot;) is JSONArray) {
                      val vods = ArrayList&lt;Vod&gt;()
                      val tempResult = result.getJSONArray(&quot;data&quot;)
                      Log.i(&quot;VodViewModel&quot;, &quot;onTaskCompleted: ${tempResult.length()}&quot;) // always 14
                      for (jsonObject in tempResult) {
                          Log.i(&quot;VodViewModel&quot;, &quot;onTaskCompleted: $jsonObject&quot;) // can't show it to you but it looks as expected
                          vods.add(Vod.fromJsonObject(jsonObject)) // this method just parses JSONObject and I confirmed that its working properly
                          //loop stops
                          Log.i(&quot;VodViewModel&quot;, &quot;onTaskCompleted: ${vods[0]}&quot;) // I tried to look if it was added but it never showed in logcat and there was never any error from this method
                      }
                      Log.i(&quot;VodViewModel&quot;, &quot;onTaskCompleted: after for&quot;) // never was reached
                      listener.done(vods, result.getInt(&quot;total_items&quot;))
                  }
  </code></pre>
  <p>And here is the iterator for JSONArray...</p>
  <pre><code>operator fun JSONArray.iterator(): Iterator&lt;JSONObject&gt;
              = (0 until length()).asSequence().map { get(it) as JSONObject }.iterator()
  </code></pre>
  <p>I'm using Executor to start this runnable on seperate thread and I don't really know what is happening, I'm not experienced with threads so anything might help.</p>