{ // Coroutine that will be canceled when the ViewModel is cleared. } } } class MyFragment: Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) viewLifecycleOwner.lifecycleScope.launch { // Coroutine that will be canceled when when the Lifecycle is destroyed. } } }
in 1..3) { delay(100) // pretend we are asynchronously waiting 100 ms emit(i) // emit next value } } fun main() = runBlocking<Unit> { simple().collect { value -> delay(300) // pretend we are processing it for 300 ms println(value) } }