Merge pull request #18977 from Snuffleupagus/api-ReaderHeadersReady-simplify
Simplify the "ReaderHeadersReady" message-handler in the API
This commit is contained in:
commit
9870099e90
@ -2646,32 +2646,27 @@ class WorkerTransport {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
messageHandler.on("ReaderHeadersReady", data => {
|
messageHandler.on("ReaderHeadersReady", async data => {
|
||||||
const headersCapability = Promise.withResolvers();
|
await this._fullReader.headersReady;
|
||||||
const fullReader = this._fullReader;
|
|
||||||
fullReader.headersReady.then(() => {
|
const { isStreamingSupported, isRangeSupported, contentLength } =
|
||||||
// If stream or range are disabled, it's our only way to report
|
this._fullReader;
|
||||||
// loading progress.
|
|
||||||
if (!fullReader.isStreamingSupported || !fullReader.isRangeSupported) {
|
// If stream or range are disabled, it's our only way to report
|
||||||
if (this._lastProgress) {
|
// loading progress.
|
||||||
loadingTask.onProgress?.(this._lastProgress);
|
if (!isStreamingSupported || !isRangeSupported) {
|
||||||
}
|
if (this._lastProgress) {
|
||||||
fullReader.onProgress = evt => {
|
loadingTask.onProgress?.(this._lastProgress);
|
||||||
loadingTask.onProgress?.({
|
|
||||||
loaded: evt.loaded,
|
|
||||||
total: evt.total,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
this._fullReader.onProgress = evt => {
|
||||||
|
loadingTask.onProgress?.({
|
||||||
|
loaded: evt.loaded,
|
||||||
|
total: evt.total,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
headersCapability.resolve({
|
return { isStreamingSupported, isRangeSupported, contentLength };
|
||||||
isStreamingSupported: fullReader.isStreamingSupported,
|
|
||||||
isRangeSupported: fullReader.isRangeSupported,
|
|
||||||
contentLength: fullReader.contentLength,
|
|
||||||
});
|
|
||||||
}, headersCapability.reject);
|
|
||||||
|
|
||||||
return headersCapability.promise;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
messageHandler.on("GetRangeReader", (data, sink) => {
|
messageHandler.on("GetRangeReader", (data, sink) => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user