title: Is the collect function of Flow a block function in Kotlin?
body: <p>I hope to delete records by Id list and relative files with Room.</p>
  <p>I find the files can be deleted and the records can't be deleted when I run Code A</p>
  <p>I find the records can be deleted when I run Code B.</p>
  <p>It seems that <code>Log.e(&quot;My&quot;,&quot;Fire&quot;)</code> is not launched in Code A. I don't know why?</p>
  <p><strong>Q1:</strong> What's wrong with Code A ?</p>
  <p><strong>Q2:</strong> Is the <code>collect</code> a block function when I use Flow?</p>
  <p><strong>Q3:</strong>  Is <code>fun getByID(id:Int): Flow&lt;RecordEntity?&gt;</code>  good design? maybe it should be <code>fun getByID(id:Int): RecordEntity?</code> .</p>
  <p><strong>Code A</strong></p>
  <pre><code>class RecordRepository @Inject constructor(
      private val mRecordDao:RecordDao
  ) {   
      override fun getByID(id:Int): Flow&lt;MRecord?&gt; =  mRecordDao.getByID(id).map {it?.let{ModelMapper.entityToModel(it) } }
   
  
      override suspend fun deleteRecord(idList: List&lt;Int&gt;) = withContext(Dispatchers.Default) {
          idList.forEach{
              getByID(it).collect {
                 it?.let {
                     val filename = it.soundFileName
                     deleteFileOrFolder(filename)
                 }
              }
          }
          Log.e(&quot;My&quot;,&quot;Fire&quot;)
          mRecordDao.deleteRecord(idList)
      }
  
  }
  
  @Dao
  interface  RecordDao {
      @Query(&quot;SELECT * FROM record_table where id=:id&quot;)
      fun getByID(id:Int): Flow&lt;RecordEntity?&gt; 
  
      @Query(&quot;delete from record_table where id in (:idList)&quot;)
      suspend fun deleteRecord(idList: List&lt;Int&gt;)
  }
  </code></pre>
  <p><strong>Code B</strong></p>
  <pre><code>class RecordRepository @Inject constructor(
      private val mRecordDao:RecordDao
  ) {   
      override fun getByID(id:Int): Flow&lt;MRecord?&gt; =  mRecordDao.getByID(id).map {it?.let{ModelMapper.entityToModel(it) } }
  
  
      override suspend fun deleteRecord(idList: List&lt;Int&gt;) = withContext(Dispatchers.Default) { 
          mRecordDao.deleteRecord(idList)
      }
  
  }
  
  //The same
  </code></pre>
  <p><strong>Added Content:</strong></p>
  <p>To Arpit Shukla: Thanks!</p>
  <p>I find many query samples to return Flow data with Room using Code C.</p>
  <p>I think Code D is enought and it's simple</p>
  <p>I'm confused why I need to use Flow in Room, you know I only want the entities once  mostly, could you tell me?</p>
  <p><strong>Code C</strong></p>
  <pre><code>@Dao
  interface  RecordDao {
      @Query(&quot;SELECT * FROM record_table ORDER BY createdDate desc&quot;)
      fun listRecord():  Flow&lt;List&lt;RecordEntity&gt;&gt;
  }
  </code></pre>
  <p><strong>Code D</strong></p>
  <pre><code>@Dao
  interface  RecordDao {
      @Query(&quot;SELECT * FROM record_table ORDER BY createdDate desc&quot;)
      suspend  fun listRecord(): List&lt;RecordEntity&gt;
  }
  </code></pre>