Skip to content

Commit 8fba3a3

Browse files
committed
fix delay
1 parent fcd46a6 commit 8fba3a3

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/notifications/NotificationPollingService.kt

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ import com.intellij.openapi.components.Storage
1313
import com.intellij.util.Alarm
1414
import com.intellij.util.AlarmFactory
1515
import com.intellij.util.io.HttpRequests
16-
import kotlinx.coroutines.CoroutineScope
1716
import kotlinx.coroutines.cancel
1817
import kotlinx.coroutines.delay
19-
import kotlinx.coroutines.launch
18+
import kotlinx.coroutines.runBlocking
2019
import org.jetbrains.annotations.VisibleForTesting
2120
import software.aws.toolkits.core.utils.RemoteResolveParser
2221
import software.aws.toolkits.core.utils.RemoteResource
@@ -25,7 +24,6 @@ import software.aws.toolkits.core.utils.getLogger
2524
import software.aws.toolkits.core.utils.warn
2625
import software.aws.toolkits.jetbrains.core.DefaultRemoteResourceResolverProvider
2726
import software.aws.toolkits.jetbrains.core.RemoteResourceResolverProvider
28-
import software.aws.toolkits.jetbrains.core.coroutines.getCoroutineBgContext
2927
import software.aws.toolkits.telemetry.Component
3028
import software.aws.toolkits.telemetry.ToolkitTelemetry
3129
import java.io.InputStream
@@ -94,7 +92,6 @@ internal final class NotificationPollingService : Disposable {
9492
private val isFirstPoll = AtomicBoolean(true)
9593
private val observers = mutableListOf<() -> Unit>()
9694
private val alarm = AlarmFactory.getInstance().create(Alarm.ThreadToUse.POOLED_THREAD, this)
97-
private val scope = CoroutineScope(getCoroutineBgContext())
9895
private val pollingIntervalMs = Duration.ofMinutes(10).toMillis()
9996
private val resourceResolver: RemoteResourceResolverProvider = DefaultRemoteResourceResolverProvider()
10097
private val notificationsResource = object : RemoteResource {
@@ -104,7 +101,7 @@ internal final class NotificationPollingService : Disposable {
104101
}
105102

106103
fun startPolling() {
107-
val newNotifications = pollForNotifications()
104+
val newNotifications = runBlocking { pollForNotifications() }
108105
if (newNotifications) {
109106
notifyObservers()
110107
}
@@ -118,7 +115,7 @@ internal final class NotificationPollingService : Disposable {
118115
* Main polling function that checks for updates and downloads if necessary
119116
* Returns the parsed notifications if successful, null otherwise
120117
*/
121-
private fun pollForNotifications(): Boolean {
118+
private suspend fun pollForNotifications(): Boolean {
122119
var retryCount = 0
123120
var lastException: Exception? = null
124121

@@ -144,9 +141,7 @@ internal final class NotificationPollingService : Disposable {
144141
retryCount++
145142
if (retryCount < MAX_RETRIES) {
146143
val backoffDelay = RETRY_DELAY_MS * (1L shl (retryCount - 1))
147-
scope.launch {
148-
delay(backoffDelay)
149-
}
144+
delay(backoffDelay)
150145
}
151146
}
152147
}
@@ -187,7 +182,6 @@ internal final class NotificationPollingService : Disposable {
187182

188183
override fun dispose() {
189184
alarm.dispose()
190-
scope.cancel()
191185
}
192186

193187
companion object {

0 commit comments

Comments
 (0)