Skip to content

Commit

Permalink
Simplify the "ReaderHeadersReady" message-handler in the API
Browse files Browse the repository at this point in the history
We can just return the existing Promise directly, and don't need to create a temporary one with `Promise.withResolvers()`.
Given the age of this code it shouldn't hurt to simplify it a little bit.
  • Loading branch information
Snuffleupagus committed Oct 29, 2024
1 parent 3a85479 commit d0eab86
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions src/display/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -2647,12 +2647,15 @@ class WorkerTransport {
});

messageHandler.on("ReaderHeadersReady", data => {
const headersCapability = Promise.withResolvers();
const fullReader = this._fullReader;
fullReader.headersReady.then(() => {

return fullReader.headersReady.then(() => {
const { isStreamingSupported, isRangeSupported, contentLength } =
fullReader;

// If stream or range are disabled, it's our only way to report
// loading progress.
if (!fullReader.isStreamingSupported || !fullReader.isRangeSupported) {
if (!isStreamingSupported || !isRangeSupported) {
if (this._lastProgress) {
loadingTask.onProgress?.(this._lastProgress);
}
Expand All @@ -2664,14 +2667,8 @@ class WorkerTransport {
};
}

headersCapability.resolve({
isStreamingSupported: fullReader.isStreamingSupported,
isRangeSupported: fullReader.isRangeSupported,
contentLength: fullReader.contentLength,
});
}, headersCapability.reject);

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

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

0 comments on commit d0eab86

Please sign in to comment.