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

Make fromApplication call non-blocking the UI thread #94

Merged
merged 1 commit into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[versions]
androidGradle = "8.1.0"
androidGradle = "8.2.2"
androidxActivity = "1.5.0"
androidxAppCompat = "1.3.1"
androidxCompose = "1.6.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import androidx.startup.Initializer
import androidx.work.Configuration
import androidx.work.WorkManager
import com.deliveryhero.whetstone.Whetstone
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.runBlocking

public class WhetstoneWorkerInitializer : Initializer<WorkManager> {

Expand All @@ -21,9 +23,11 @@ public class WhetstoneWorkerInitializer : Initializer<WorkManager> {


private fun Whetstone.installWorkerFactory(application: Application) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

random thought, non-blocking. is there merit to making this function a suspending function called in a coroutine scope? those are also non-blocking even when called on the main thread. cc @vsdeni

val parentComponent = fromApplication<WorkerComponent.ParentComponent>(application)
val configuration = Configuration.Builder()
.setWorkerFactory(parentComponent.getWorkerFactory())
.build()
val configuration = runBlocking(Dispatchers.IO) {
val parentComponent = fromApplication<WorkerComponent.ParentComponent>(application)
return@runBlocking Configuration.Builder()
.setWorkerFactory(parentComponent.getWorkerFactory())
.build()
}
WorkManager.initialize(application, configuration)
}
Loading