Skip to content

Commit cc02c33

Browse files
committed
coroutine scope delay instead of thread.sleep
1 parent 6c76ec4 commit cc02c33

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ import com.intellij.openapi.components.Storage
1414
import com.intellij.util.Alarm
1515
import com.intellij.util.AlarmFactory
1616
import com.intellij.util.io.HttpRequests
17+
import kotlinx.coroutines.CoroutineScope
18+
import kotlinx.coroutines.Dispatchers
19+
import kotlinx.coroutines.cancel
20+
import kotlinx.coroutines.delay
21+
import kotlinx.coroutines.launch
1722
import software.aws.toolkits.core.utils.RemoteResolveParser
1823
import software.aws.toolkits.core.utils.RemoteResource
1924
import software.aws.toolkits.core.utils.error
@@ -60,6 +65,7 @@ class NotificationPollingService : Disposable {
6065
private val firstPollDone = AtomicBoolean(false)
6166
private val observers = mutableListOf<() -> Unit>()
6267
private val alarm = AlarmFactory.getInstance().create(Alarm.ThreadToUse.POOLED_THREAD, this)
68+
private val scope = CoroutineScope(Dispatchers.Default)
6369
private val pollingIntervalMs = Duration.ofMinutes(10).toMillis()
6470
private val resourceResolver: RemoteResourceResolverProvider = DefaultRemoteResourceResolverProvider()
6571
private val notificationsResource = object : RemoteResource {
@@ -108,7 +114,9 @@ class NotificationPollingService : Disposable {
108114
retryCount++
109115
if (retryCount < MAX_RETRIES) {
110116
val backoffDelay = RETRY_DELAY_MS * (1L shl (retryCount - 1))
111-
Thread.sleep(backoffDelay)
117+
scope.launch {
118+
delay(backoffDelay)
119+
}
112120
}
113121
}
114122
}
@@ -144,6 +152,7 @@ class NotificationPollingService : Disposable {
144152

145153
override fun dispose() {
146154
alarm.dispose()
155+
scope.cancel()
147156
}
148157

149158
companion object {

0 commit comments

Comments
 (0)