()
| 248 | } |
| 249 | |
| 250 | function poll(): Promise<void> { |
| 251 | status = 'running'; |
| 252 | |
| 253 | return Promise.allSettled([ |
| 254 | checkForUpdate({bridge, element, refresh, store}), |
| 255 | createPromiseWhichResolvesInOneSecond(), |
| 256 | ]) |
| 257 | .then(([{status: updateStatus, reason}]) => { |
| 258 | // There isn't much to do about errors in this case, |
| 259 | // but we should at least log them, so they aren't silent. |
| 260 | // Log only if polling is still active, we can't handle the case when |
| 261 | // request was sent, and then bridge was remounted (for example, when user did navigate to a new page), |
| 262 | // but at least we can mark that polling was aborted |
| 263 | if (updateStatus === 'rejected' && status !== 'aborted') { |
| 264 | // This is expected Promise rejection, no need to log it |
| 265 | if (reason instanceof ElementPollingCancellationError) { |
| 266 | return; |
| 267 | } |
| 268 | |
| 269 | console.error(reason); |
| 270 | } |
| 271 | }) |
| 272 | .finally(() => { |
| 273 | const shouldContinuePolling = |
| 274 | status !== 'aborted' && status !== 'paused'; |
| 275 | |
| 276 | status = 'idle'; |
| 277 | |
| 278 | if (shouldContinuePolling) { |
| 279 | return poll(); |
| 280 | } |
| 281 | }); |
| 282 | } |
| 283 | |
| 284 | poll(); |
| 285 |
no test coverage detected