title: End flow/coroutines task before go further null issue
body: <p>Fragment</p>
  <pre><code>   private fun makeApiRequest() {
          vm.getRandomPicture()
          var pictureElement = vm.setRandomPicture()
  
          GlobalScope.launch(Dispatchers.Main) {
              // what about internet
              if (pictureElement != null &amp;&amp; pictureElement!!.fileSizeBytes!! &lt; 400000) {
  
                  Glide.with(requireContext()).load(pictureElement!!.url)
                      .into(layout.ivRandomPicture)
                  layout.ivRandomPicture.visibility = View.VISIBLE
              } else {
                  getRandomPicture()
              }
          }
      }
  </code></pre>
  <p>viewmodel</p>
  <pre><code>    fun getRandomPicture() {
          viewModelScope.launch {
              getRandomPictureItemUseCase.build(Unit).collect {
                  pictureElement.value = it
                  Log.d(&quot;inspirationquotes&quot;, &quot;VIEWMODEL $pictureElement&quot;)
                  Log.d(&quot;inspirationquotes&quot;, &quot;VIEWMODEL VALUE ${pictureElement.value}&quot;)
              }
          }
      }
  
      fun setRandomPicture(): InspirationQuotesDetailsResponse? {
              return pictureElement.value
      }
  </code></pre>
  <p>Flow UseCase</p>
  <pre><code>class GetRandomPictureItemUseCase @Inject constructor(private val api: InspirationQuotesApi): BaseFlowUseCase&lt;Unit, InspirationQuotesDetailsResponse&gt;() {
      override fun create(params: Unit): Flow&lt;InspirationQuotesDetailsResponse&gt; {
          return flow{
              emit(api.getRandomPicture())
          }
      }
  }
  </code></pre>
  <p>My flow task from viewmodel doesn't goes on time. I do not know how to achieve smooth downloading data from Api and provide it further.
  I was reading I could use runBlocking, but it is not recommended in production as well.
  What do you use in your professional applications to achieve nice app?</p>
  <p>Now the effect is that that image doesn't load or I have null error beacause of my Log.d before GlobalScope in Fragment (it is not in code right now).</p>
  <p>One more thing is definding null object I do not like it, what do you think?</p>
  <pre><code>    var pictureElement = MutableStateFlow&lt;InspirationQuotesDetailsResponse?&gt;(null)
  </code></pre>
  <p>EDIT:</p>
  <p>Viewmodel</p>
  <pre><code> val randomPicture: Flow&lt;InspirationQuotesDetailsResponse&gt; = getRandomPictureItemUseCase.build(Unit)
  
  </code></pre>
  <p>fragment</p>
  <pre><code>private fun makeApiRequest() = lifecycleScope.launch {
              vm.randomPicture
                  .flowWithLifecycle(lifecycle, Lifecycle.State.STARTED)
                  .collect { response -&gt;
                      if (response.fileSizeBytes &lt; 600000) {
                          Log.d(&quot;fragment&quot;, &quot;itGetsValue&quot;)
                          Glide.with(requireContext()).load(response.url)
                              .into(layout.ivRandomPicture)
                          layout.ivRandomPicture.visibility = View.VISIBLE
                      } else {
                          onFloatingActionClick()
                      }
                  }
      }
  </code></pre>
  <p>Edit2 problem on production, another topic:
  Link -&gt; <a href="https://stackoverflow.com/questions/70668103/what-is-the-substitute-for-runblocking-coroutines-in-fragments-and-activities">What is the substitute for runBlocking Coroutines in fragments and activities?</a></p>