|
2 | 2 | import React from 'react'; |
3 | 3 | import PropTypes from 'prop-types'; |
4 | 4 | // eslint-disable-next-line import/no-unresolved |
5 | | -import PQueue from 'p-queue'; |
| 5 | +import PQueue, { TimeoutError } from 'p-queue'; |
6 | 6 | import { Progress } from 'reactstrap'; |
7 | 7 | import LoadingIndicator from './loading-indicator'; |
8 | 8 | import util from '../../util/util'; |
@@ -304,26 +304,32 @@ class PlayQueue extends React.Component { |
304 | 304 | this.inQueueObject[strDate] = date; |
305 | 305 | this.bufferArray.push(strDate); |
306 | 306 |
|
307 | | - await this.queue.add(async () => { |
308 | | - const startTime = Date.now(); |
309 | | - await promiseImageryForTime(date); |
310 | | - const elapsedTime = Date.now() - startTime; |
311 | | - const fetchTime = elapsedTime >= MIN_REQUEST_TIME_MS ? elapsedTime : MIN_REQUEST_TIME_MS; |
312 | | - this.fetchTimes.push(fetchTime); |
313 | | - this.setState({ loadedItems: loadedItems += 1 }); |
| 307 | + try { |
| 308 | + await this.queue.add(async () => { |
| 309 | + const startTime = Date.now(); |
| 310 | + await promiseImageryForTime(date); |
| 311 | + const elapsedTime = Date.now() - startTime; |
| 312 | + const fetchTime = elapsedTime >= MIN_REQUEST_TIME_MS ? elapsedTime : MIN_REQUEST_TIME_MS; |
| 313 | + this.fetchTimes.push(fetchTime); |
| 314 | + this.setState({ loadedItems: loadedItems += 1 }); |
314 | 315 |
|
315 | | - if (!this.mounted) return; |
316 | | - this.bufferObject[strDate] = strDate; |
317 | | - delete this.inQueueObject[strDate]; |
318 | | - const currentBufferSize = util.objectLength(this.bufferObject); |
| 316 | + if (!this.mounted) return; |
| 317 | + this.bufferObject[strDate] = strDate; |
| 318 | + delete this.inQueueObject[strDate]; |
| 319 | + const currentBufferSize = util.objectLength(this.bufferObject); |
319 | 320 |
|
320 | | - if (!initialLoad || this.canPreloadAll || currentBufferSize >= this.initialBufferSize) { |
321 | | - this.checkQueue(); |
322 | | - this.checkShouldPlay(); |
323 | | - } |
| 321 | + if (!initialLoad || this.canPreloadAll || currentBufferSize >= this.initialBufferSize) { |
| 322 | + this.checkQueue(); |
| 323 | + this.checkShouldPlay(); |
| 324 | + } |
324 | 325 |
|
325 | | - return strDate; |
326 | | - }); |
| 326 | + return strDate; |
| 327 | + }); |
| 328 | + } catch (error) { |
| 329 | + if (error instanceof TimeoutError) { |
| 330 | + console.error('Imagery loading timed out after 3 seconds'); |
| 331 | + } |
| 332 | + } |
327 | 333 | } |
328 | 334 |
|
329 | 335 | play() { |
|
0 commit comments