Skip to content

Commit ec0cf30

Browse files
committed
update settings fetch logic to use the new pause and resume functions
1 parent 60bc4ea commit ec0cf30

File tree

1 file changed

+15
-19
lines changed
  • core/src/main/java/com/segment/analytics/kotlin/core

1 file changed

+15
-19
lines changed

core/src/main/java/com/segment/analytics/kotlin/core/Settings.kt

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -84,31 +84,27 @@ suspend fun Analytics.checkSettings() {
8484
val writeKey = configuration.writeKey
8585
val cdnHost = configuration.cdnHost
8686

87-
store.currentState(System::class) ?: return
88-
store.dispatch(System.ToggleRunningAction(running = false), System::class)
87+
pauseEventProcessing()
8988

90-
withContext(networkIODispatcher) {
89+
val settingsObj = withContext(networkIODispatcher) {
9190
log("Fetching settings on ${Thread.currentThread().name}")
92-
val settingsObj: Settings? = fetchSettings(writeKey, cdnHost)
93-
94-
withContext(analyticsDispatcher) {
95-
96-
settingsObj?.let {
97-
log("Dispatching update settings on ${Thread.currentThread().name}")
98-
store.dispatch(System.UpdateSettingsAction(settingsObj), System::class)
99-
}
91+
return@withContext fetchSettings(writeKey, cdnHost)
92+
}
10093

101-
store.currentState(System::class)?.let { system ->
102-
system.settings?.let { settings ->
103-
log("Propagating settings on ${Thread.currentThread().name}")
104-
update(settings)
105-
}
106-
}
94+
settingsObj?.let {
95+
log("Dispatching update settings on ${Thread.currentThread().name}")
96+
store.dispatch(System.UpdateSettingsAction(settingsObj), System::class)
97+
}
10798

108-
// we're good to go back to a running state.
109-
store.dispatch(System.ToggleRunningAction(running = true), System::class)
99+
store.currentState(System::class)?.let { system ->
100+
system.settings?.let { settings ->
101+
log("Propagating settings on ${Thread.currentThread().name}")
102+
update(settings)
110103
}
111104
}
105+
106+
// we're good to go back to a running state.
107+
resumeEventProcessing()
112108
}
113109

114110
internal fun Analytics.fetchSettings(

0 commit comments

Comments
 (0)