How to wait for flow to return before sending intent

Solution 1:

Try to send the broadcast in onEach function block, it should work:

mainRepository.refreshAll()
        .onEach { hashMap ->
            intent.putExtra("hashMap", hashMap)
            sendBroadcast(intent)
        }
        .launchIn(serviceScope)