title: Kotlin Coroutines Run blocking not working as expected and Cannot block execution of for loops
body: <p>In my app i'm executing two for loops however those for loops need to scheduled in a order here is the use case:</p>
  
  <p>There are two for loops :
  1- ImageStickerslist
  2-TextStickerslist</p>
  
  <p>What i want to do is after imagestickerslist if properly finised only then textstickerslist will be executed.  </p>
  
  <p>Here imagesticker list consists of url path which is used to load images from glide however if those images are of high resolution it eventually makes the thread continue even if the image is not yet loaded from url. To solve this tried adding blocking calls to glide on ready and full method but it won't prove to be of any help. I'm very confused how blocking calls work any help into this will be really appreciated.</p>
  
  <p>Here's my code where for loops are executed:</p>
  
  <pre><code> runBlocking {
                              launch {
                                  imagestickers.forEach {
                                      runBlocking {
                                          var image = it.path
                                          var x = it.x
                                          var y = it.y
                                          image!!.log()
                                          setimagestickers(image!!, x!!, y!!, it.width!!, it.height!!)
                                      }
                                  }
                              }.join()
                              textstickers.forEach {
                                  runBlocking {
                                      var text = it.text.toString()
                                      var color = it.color
                                      var font = it.font
                                      var size = it.size
                                      var x = it.x
                                      var y = it.y
                                      setTextSticker(text, Color.parseColor(color), size!!, x!!, y!!)
                                  }
                              }
                          }
  </code></pre>
  
  <p>Here are my two methods where main computation is taking place:</p>
  
  <pre><code> fun setimagestickers(path:String,x:Int,y:Int,w:Int,h:Int){
  
             Glide.with(this@NewStickerActivity).asBitmap().timeout(6000000).load(path).into(object : CustomTarget&lt;Bitmap&gt;() {
                 override fun onLoadCleared(placeholder: Drawable?) {
  
                 }
  
                 override fun onResourceReady(resource: Bitmap, transition: Transition&lt;in Bitmap&gt;?) {
                     var size: ViewGroup.LayoutParams
                     var bmp1 = resource
                     size = UiHelper.getHeightWidth(this@NewStickerActivity, (w).toInt(), (h).toInt())
                     var resizedBitmap = Bitmap.createScaledBitmap(bmp1, size.width, size.height, false)
                     var drawable = BitmapDrawable(resources, resizedBitmap)
                     var dsImageSticker = DrawableSticker(drawable)
                     dsImageSticker.setTag("ImageSticker")
                     var pm: List&lt;Int&gt;
                     if (density &gt; 3.0) {
                         pm = UiHelper.getmargins(this@NewStickerActivity, (x).toInt(), (y).toInt())
                     } else {
                         pm = UiHelper.getmargins(this@NewStickerActivity, (x).toInt(), (y).toInt())
                     }
                     Log.i("Hmmm:", pm.get(0).toFloat().toString() + "::" + pm.get(1).toFloat().toString())
  
                     stickerView.addStickerAndSetMatrix1(
                             dsImageSticker,
                             pm.get(0).toFloat(),
                             pm.get(1).toFloat()
                     )
  
                 }
  
             })
      }
     fun setTextSticker(text: String, color: Int,size: Int, x: Int, y: Int){
              val bmp1: Bitmap
              val drawable: Drawable
              var l: List&lt;Int&gt;
              if (density &gt; 3.0) {
                  l = UiHelper.getmargins(this@NewStickerActivity, (x).toInt(), (y * 1.07).toInt())
              } else {
                  l = UiHelper.getmargins(this@NewStickerActivity, x.toInt(), y.toInt())
              }
              //var tf = Typeface.createFromFile(assets,"fonts/"+path)
              var tf = Typeface.createFromAsset(assets, "fonts/Myriad Pro Bold SemiExtended.ttf")
              bmp1 = createBitmapFromLayoutWithText(this@NewStickerActivity, size, text, color, 0f, tf, 0f, 0f, color, Gravity.LEFT)
              drawable = BitmapDrawable(resources, bmp1)
              var dsTextSticker = DrawableSticker(drawable)
              dsTextSticker.setTag("textSticker")
              Log.i("Hmmm:", l.get(0).toFloat().toString() + "::" + l.get(1).toFloat().toString())
              /*if (rotate) {
                  stic.addStickerAndSetrotate(
                          dsTextSticker, rotationdegress,
                          l.get(0).toFloat(),
                          l.get(1).toFloat()
                  )
              } else {*/
              stickerView.addStickerAndSetMatrix1(
                      dsTextSticker,
                      l.get(0).toFloat(),
                      l.get(1).toFloat())
  
  
  
      }
  </code></pre>
  
  <p><strong>UPDATE</strong>:</p>
  
  <p>I got this working without coroutines by incrementing and fetching images in a sequence: 
  Firstly i took a Int and then kept incrementing until it reached list size here is my code:
  Firstly i did this :</p>
  
  <pre><code>var i = 0 
  setimagestickers(imagestickers.get(i).path!!, imagestickers.get(i).x!!, imagestickers.get(i).y!!, imagestickers.get(i).width!!, imagestickers.get(i).height!!)
  </code></pre>
  
  <p>After that inside on resource ready did the trick!!</p>
  
  <pre><code>Glide.with(this@NewStickerActivity).asBitmap().timeout(6000000).load(path).into(object : CustomTarget&lt;Bitmap&gt;() {
                 override fun onLoadCleared(placeholder: Drawable?) {
  
                 }
  
                 override fun onResourceReady(resource: Bitmap, transition: Transition&lt;in Bitmap&gt;?) {
                     var size: ViewGroup.LayoutParams
                     var bmp1 = resource
                     size = UiHelper.getHeightWidth(this@NewStickerActivity, (w).toInt(), (h).toInt())
                     var resizedBitmap = Bitmap.createScaledBitmap(bmp1, size.width, size.height, false)
                     var drawable = BitmapDrawable(resources, resizedBitmap)
                     var dsImageSticker = DrawableSticker(drawable)
                     dsImageSticker.setTag("ImageSticker")
                     var pm: List&lt;Int&gt;
                     if (density &gt; 3.0) {
                         pm = UiHelper.getmargins(this@NewStickerActivity, (x).toInt(), (y).toInt())
                     } else {
                         pm = UiHelper.getmargins(this@NewStickerActivity, (x).toInt(), (y).toInt())
                     }
                     Log.i("Hmmm:", pm.get(0).toFloat().toString() + "::" + pm.get(1).toFloat().toString())
  
                     stickerView.addStickerAndSetMatrix1(
                             dsImageSticker,
                             pm.get(0).toFloat(),
                             pm.get(1).toFloat()
                     )
                  i++
                  if(i &lt; imagestickers.size){
                      setimagestickers(imagestickers.get(i).path!!, imagestickers.get(i).x!!, imagestickers.get(i).y!!, imagestickers.get(i).width!!, imagestickers.get(i).height!!)
                  }
                     else{
                      if(textstickers.isNullOrEmpty()){
                          loader!!.hide()
                      }
                      else {
                          setTextSticker(textstickers.get(j).text!!, Color.parseColor(textstickers.get(j).color), textstickers.get(j).size!!, textstickers.get(j).x!!, textstickers.get(j).y!!)
                      }
                      }
                 }
  
             })
  </code></pre>
  
  <p>However i'm still wondering how can i solve it with coroutines rather than this approach!!! </p>