@@ -13,10 +13,9 @@ import com.intellij.openapi.components.Storage
1313import com.intellij.util.Alarm
1414import com.intellij.util.AlarmFactory
1515import com.intellij.util.io.HttpRequests
16- import kotlinx.coroutines.CoroutineScope
1716import kotlinx.coroutines.cancel
1817import kotlinx.coroutines.delay
19- import kotlinx.coroutines.launch
18+ import kotlinx.coroutines.runBlocking
2019import org.jetbrains.annotations.VisibleForTesting
2120import software.aws.toolkits.core.utils.RemoteResolveParser
2221import software.aws.toolkits.core.utils.RemoteResource
@@ -25,7 +24,6 @@ import software.aws.toolkits.core.utils.getLogger
2524import software.aws.toolkits.core.utils.warn
2625import software.aws.toolkits.jetbrains.core.DefaultRemoteResourceResolverProvider
2726import software.aws.toolkits.jetbrains.core.RemoteResourceResolverProvider
28- import software.aws.toolkits.jetbrains.core.coroutines.getCoroutineBgContext
2927import software.aws.toolkits.telemetry.Component
3028import software.aws.toolkits.telemetry.ToolkitTelemetry
3129import 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