Skip to content

Commit 5d016a6

Browse files
Added timeout handling for pqueue (#6293)
1 parent 9ee2a37 commit 5d016a6

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

web/js/components/animation-widget/play-queue.js

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import React from 'react';
33
import PropTypes from 'prop-types';
44
// eslint-disable-next-line import/no-unresolved
5-
import PQueue from 'p-queue';
5+
import PQueue, { TimeoutError } from 'p-queue';
66
import { Progress } from 'reactstrap';
77
import LoadingIndicator from './loading-indicator';
88
import util from '../../util/util';
@@ -304,26 +304,32 @@ class PlayQueue extends React.Component {
304304
this.inQueueObject[strDate] = date;
305305
this.bufferArray.push(strDate);
306306

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 });
314315

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);
319320

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+
}
324325

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+
}
327333
}
328334

329335
play() {

0 commit comments

Comments
 (0)