Hi I just wonder which code snippet is better for scope while getting query result in SharedFlow
val categories = categoryRepository.getAll().shareIn(
scope = viewModelScope,
started = SharingStarted.WhileSubscribed(5000),
replay = 0
)
val categories = categoryRepository.getAll().shareIn(
scope = CoroutineScope(Dispatchers.IO),
started = SharingStarted.WhileSubscribed(5000),
replay = 0
)
CodePudding user response:
this is better
val categories = categoryRepository.getAll().shareIn(
scope = CoroutineScope(Dispatchers.IO),
started = SharingStarted.WhileSubscribed(5000),
replay = 0
)
as viewModelScope
is bound to Dispatchers.Main.immediate