Skip to content

Commit

Permalink
Make fromApplication call non-blocking the UI thread (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
denys-vasylenko committed Mar 15, 2024
1 parent 0ff5edb commit 1c21c7d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
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) {
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)
}

0 comments on commit 1c21c7d

Please sign in to comment.