Skip to content

Commit

Permalink
Merge pull request #18977 from Snuffleupagus/api-ReaderHeadersReady-s…
Browse files Browse the repository at this point in the history
…implify

Simplify the "ReaderHeadersReady" message-handler in the API
  • Loading branch information
Snuffleupagus authored Oct 29, 2024
2 parents 25cf4ad + afb4813 commit 9870099
Showing 1 changed file with 19 additions and 24 deletions.
43 changes: 19 additions & 24 deletions src/display/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -2646,32 +2646,27 @@ class WorkerTransport {
};
});

messageHandler.on("ReaderHeadersReady", data => {
const headersCapability = Promise.withResolvers();
const fullReader = this._fullReader;
fullReader.headersReady.then(() => {
// If stream or range are disabled, it's our only way to report
// loading progress.
if (!fullReader.isStreamingSupported || !fullReader.isRangeSupported) {
if (this._lastProgress) {
loadingTask.onProgress?.(this._lastProgress);
}
fullReader.onProgress = evt => {
loadingTask.onProgress?.({
loaded: evt.loaded,
total: evt.total,
});
};
}
messageHandler.on("ReaderHeadersReady", async data => {
await this._fullReader.headersReady;

headersCapability.resolve({
isStreamingSupported: fullReader.isStreamingSupported,
isRangeSupported: fullReader.isRangeSupported,
contentLength: fullReader.contentLength,
});
}, headersCapability.reject);
const { isStreamingSupported, isRangeSupported, contentLength } =
this._fullReader;

// If stream or range are disabled, it's our only way to report
// loading progress.
if (!isStreamingSupported || !isRangeSupported) {
if (this._lastProgress) {
loadingTask.onProgress?.(this._lastProgress);
}
this._fullReader.onProgress = evt => {
loadingTask.onProgress?.({
loaded: evt.loaded,
total: evt.total,
});
};
}

return headersCapability.promise;
return { isStreamingSupported, isRangeSupported, contentLength };
});

messageHandler.on("GetRangeReader", (data, sink) => {
Expand Down

0 comments on commit 9870099

Please sign in to comment.