Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Data layer codelab] Small error in 'refresh()' method in Chapter 7 #968

Open
Mario-paul opened this issue Aug 18, 2023 · 0 comments
Open

Comments

@Mario-paul
Copy link

In chapter 7 "Create the Task Repository", and in the 2nd step of section "Save and refresh network data", the code block suggests we do

suspend fun refresh() {
    val networkTasks = networkDataSource.loadTasks()
    localDataSource.deleteAll()
    val localTasks = withContext(dispatcher) {
        networkTasks.toLocal()
    }
    localDataSource.upsertAll(networkTasks.toLocal()) // THIS IS THE ERROR
}

as you can see, localTasks is pointless here because you are doing the same thing in the erroneous line but you are also blocking the main thread. Instead, it should look like this

suspend fun refresh() {
    val networkTasks = networkDataSource.loadTasks()
    localDataSource.deleteAll()
    val localTasks = withContext(dispatcher) {
        networkTasks.toLocal()
    }
    localDataSource.upsertAll(localTasks) // CORRECTED LINE
}
@Mario-paul Mario-paul changed the title [Data layer codelab] Small error in code in Chapter 7 [Data layer codelab] Small error in 'refresh()' method in Chapter 7 Aug 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant