Issue
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
)
Solution
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
Answered By - End User
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.