Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 24 additions & 18 deletions web/js/components/animation-widget/play-queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import React from 'react';
import PropTypes from 'prop-types';
// eslint-disable-next-line import/no-unresolved
import PQueue from 'p-queue';
import PQueue, { TimeoutError } from 'p-queue';
import { Progress } from 'reactstrap';
import LoadingIndicator from './loading-indicator';
import util from '../../util/util';
Expand Down Expand Up @@ -137,7 +137,7 @@
/**
* Gets the last date that should be added to the queue
*/
getLastInQueue = function() {

Check warning on line 140 in web/js/components/animation-widget/play-queue.js

View workflow job for this annotation

GitHub Actions / windows-latest, Node 24

Unexpected unnamed method 'getLastInQueue'

Check warning on line 140 in web/js/components/animation-widget/play-queue.js

View workflow job for this annotation

GitHub Actions / macOS-latest, Node 24

Unexpected unnamed method 'getLastInQueue'

Check warning on line 140 in web/js/components/animation-widget/play-queue.js

View workflow job for this annotation

GitHub Actions / ubuntu-latest, Node 24

Unexpected unnamed method 'getLastInQueue'
const { isLoopActive, startDate, endDate } = this.props;
let currentDate = toDate(this.playingDate);
const currentBufferSize = util.objectLength(this.bufferObject);
Expand Down Expand Up @@ -304,26 +304,32 @@
this.inQueueObject[strDate] = date;
this.bufferArray.push(strDate);

await this.queue.add(async () => {
const startTime = Date.now();
await promiseImageryForTime(date);
const elapsedTime = Date.now() - startTime;
const fetchTime = elapsedTime >= MIN_REQUEST_TIME_MS ? elapsedTime : MIN_REQUEST_TIME_MS;
this.fetchTimes.push(fetchTime);
this.setState({ loadedItems: loadedItems += 1 });
try {
await this.queue.add(async () => {
const startTime = Date.now();
await promiseImageryForTime(date);
const elapsedTime = Date.now() - startTime;
const fetchTime = elapsedTime >= MIN_REQUEST_TIME_MS ? elapsedTime : MIN_REQUEST_TIME_MS;
this.fetchTimes.push(fetchTime);
this.setState({ loadedItems: loadedItems += 1 });

if (!this.mounted) return;
this.bufferObject[strDate] = strDate;
delete this.inQueueObject[strDate];
const currentBufferSize = util.objectLength(this.bufferObject);
if (!this.mounted) return;
this.bufferObject[strDate] = strDate;
delete this.inQueueObject[strDate];
const currentBufferSize = util.objectLength(this.bufferObject);

if (!initialLoad || this.canPreloadAll || currentBufferSize >= this.initialBufferSize) {
this.checkQueue();
this.checkShouldPlay();
}
if (!initialLoad || this.canPreloadAll || currentBufferSize >= this.initialBufferSize) {
this.checkQueue();
this.checkShouldPlay();
}

return strDate;
});
return strDate;
});
} catch (error) {
if (error instanceof TimeoutError) {
console.error('Imagery loading timed out after 3 seconds');
}
}
}

play() {
Expand Down
Loading