Skip to content

Commit

Permalink
Cache fetch promise and clear on error
Browse files Browse the repository at this point in the history
  • Loading branch information
jcphill committed Aug 2, 2023
1 parent 475d91e commit fc41154
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/geotiffimage.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,12 +382,12 @@ class GeoTIFFImage {
offset = this.fileDirectory.StripOffsets[index];
byteCount = this.fileDirectory.StripByteCounts[index];
}
const slice = (await this.source.fetch([{ offset, length: byteCount }], signal))[0];

let request;
if (tiles === null || !tiles[index]) {
// resolve each request by potentially applying array normalization
request = (async () => {
const slice = (await this.source.fetch([{ offset, length: byteCount }], signal))[0];
let data = await poolOrDecoder.decode(this.fileDirectory, slice);
const sampleFormat = this.getSampleFormat();
const bitsPerSample = this.getBitsPerSample();
Expand All @@ -408,6 +408,11 @@ class GeoTIFFImage {
// set the cache
if (tiles !== null) {
tiles[index] = request;
request.catch(() => {
if (tiles[index] === request) {
tiles[index] = null;
}
});
}
} else {
// get from the cache
Expand Down

0 comments on commit fc41154

Please sign in to comment.