Skip to content

Commit

Permalink
Adding error handling on block requests
Browse files Browse the repository at this point in the history
  • Loading branch information
constantinius committed Feb 19, 2021
1 parent baaa1e6 commit 07ed101
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions src/source/blockedsource.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,19 +114,22 @@ export class BlockedSource extends BaseSource {
for (const blockId of group.blockIds) {
// make an async IIFE for each block
const blockRequest = (async () => {
const response = (await groupRequests)[groupIndex];
const blockOffset = blockId * this.blockSize;
const o = blockOffset - response.offset;
const t = Math.min(o + this.blockSize, response.data.byteLength);
const data = response.data.slice(o, t);
const block = new Block(
blockOffset,
data.byteLength,
data,
);
this.blockRequests.delete(blockId);
this.blockCache.set(blockId, block);
return block;
try {
const response = (await groupRequests)[groupIndex];
const blockOffset = blockId * this.blockSize;
const o = blockOffset - response.offset;
const t = Math.min(o + this.blockSize, response.data.byteLength);
const data = response.data.slice(o, t);
const block = new Block(
blockOffset,
data.byteLength,
data,
);
this.blockCache.set(blockId, block);
return block;
} finally {
this.blockRequests.delete(blockId);
}
})();
this.blockRequests.set(blockId, blockRequest);
}
Expand Down

0 comments on commit 07ed101

Please sign in to comment.