Since refresh is mostly a CPU/Memory process and not really IO, Default is recommended.

This commit is contained in:
Vitor Pamplona 2023-02-06 12:29:17 -05:00
parent 074cac3021
commit f160a024aa
3 changed files with 11 additions and 6 deletions

View File

@ -30,10 +30,12 @@ class CardFeedViewModel(val dataSource: NostrDataSource<Note>): ViewModel() {
private var lastNotes: List<Note>? = null
suspend fun refresh() = withContext(Dispatchers.IO) {
refreshSuspended()
fun refresh() {
val scope = CoroutineScope(Job() + Dispatchers.Default)
scope.launch {
refreshSuspended()
}
}
private fun refreshSuspended() {
val notes = dataSource.loadTop()

View File

@ -83,7 +83,7 @@ abstract class FeedViewModel(val dataSource: NostrDataSource<Note>): ViewModel()
}
fun refresh() {
viewModelScope.launch(Dispatchers.IO) {
viewModelScope.launch(Dispatchers.Default) {
val notes = newListFromDataSource()
val oldNotesState = feedContent.value

View File

@ -41,8 +41,11 @@ open class UserFeedViewModel(val dataSource: NostrDataSource<User>): ViewModel()
private val _feedContent = MutableStateFlow<UserFeedState>(UserFeedState.Loading)
val feedContent = _feedContent.asStateFlow()
suspend fun refresh() = withContext(Dispatchers.IO) {
refreshSuspended()
fun refresh() {
val scope = CoroutineScope(Job() + Dispatchers.Default)
scope.launch {
refreshSuspended()
}
}