1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 export class NetworkDecodedBodySizeMap {
6 #channelIdToBodySizePromiseMap;
9 this.#channelIdToBodySizePromiseMap = new Map();
13 this.#channelIdToBodySizePromiseMap = null;
16 async getDecodedBodySize(channelId) {
17 if (!this.#channelIdToBodySizePromiseMap.has(channelId)) {
18 const { promise, resolve } = Promise.withResolvers();
19 this.#channelIdToBodySizePromiseMap.set(channelId, {
26 const mapEntry = this.#channelIdToBodySizePromiseMap.get(channelId);
27 return mapEntry.decodedBodySize;
30 setDecodedBodySize(channelId, decodedBodySize) {
31 if (!this.#channelIdToBodySizePromiseMap.has(channelId)) {
32 const { promise, resolve } = Promise.withResolvers();
33 this.#channelIdToBodySizePromiseMap.set(channelId, {
39 const mapEntry = this.#channelIdToBodySizePromiseMap.get(channelId);
41 mapEntry.decodedBodySize = decodedBodySize;
42 mapEntry.resolve(decodedBodySize);
46 this.#channelIdToBodySizePromiseMap.delete(channelId);