mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-30 16:22:00 +00:00
414f5942e5
Differential Revision: https://phabricator.services.mozilla.com/D203134
49 lines
1.4 KiB
JavaScript
49 lines
1.4 KiB
JavaScript
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
export class NetworkDecodedBodySizeMap {
|
|
#channelIdToBodySizePromiseMap;
|
|
|
|
constructor() {
|
|
this.#channelIdToBodySizePromiseMap = new Map();
|
|
}
|
|
|
|
destroy() {
|
|
this.#channelIdToBodySizePromiseMap = null;
|
|
}
|
|
|
|
async getDecodedBodySize(channelId) {
|
|
if (!this.#channelIdToBodySizePromiseMap.has(channelId)) {
|
|
const { promise, resolve } = Promise.withResolvers();
|
|
this.#channelIdToBodySizePromiseMap.set(channelId, {
|
|
promise,
|
|
resolve,
|
|
});
|
|
|
|
await promise;
|
|
}
|
|
const mapEntry = this.#channelIdToBodySizePromiseMap.get(channelId);
|
|
return mapEntry.decodedBodySize;
|
|
}
|
|
|
|
setDecodedBodySize(channelId, decodedBodySize) {
|
|
if (!this.#channelIdToBodySizePromiseMap.has(channelId)) {
|
|
const { promise, resolve } = Promise.withResolvers();
|
|
this.#channelIdToBodySizePromiseMap.set(channelId, {
|
|
decodedBodySize,
|
|
promise,
|
|
resolve,
|
|
});
|
|
}
|
|
const mapEntry = this.#channelIdToBodySizePromiseMap.get(channelId);
|
|
|
|
mapEntry.decodedBodySize = decodedBodySize;
|
|
mapEntry.resolve(decodedBodySize);
|
|
}
|
|
|
|
delete(channelId) {
|
|
this.#channelIdToBodySizePromiseMap.delete(channelId);
|
|
}
|
|
}
|