mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-14 22:17:03 +05:30
android: fetch posts on the IO Dispatcher
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
parent
61e1deb478
commit
eee64b151a
1 changed files with 3 additions and 1 deletions
|
@ -3,6 +3,8 @@ package dev.msfjarvis.claw.android.paging
|
|||
import androidx.paging.PagingSource
|
||||
import androidx.paging.PagingState
|
||||
import dev.msfjarvis.claw.api.model.LobstersPost
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
class LobstersPagingSource(
|
||||
private val getMorePosts: suspend (Int) -> List<LobstersPost>,
|
||||
|
@ -11,7 +13,7 @@ class LobstersPagingSource(
|
|||
override suspend fun load(params: LoadParams<Int>): LoadResult<Int, LobstersPost> {
|
||||
return try {
|
||||
val page = params.key ?: 1
|
||||
val posts = getMorePosts(page)
|
||||
val posts = withContext(Dispatchers.IO) { getMorePosts(page) }
|
||||
|
||||
LoadResult.Page(
|
||||
data = posts,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue