* Returns maybe a promise if lazy. * @param {string} reason explanation why unpack is necessary * @returns {void | Promise<void>} maybe a promise if lazy
(reason)
| 950 | * @returns {void | Promise<void>} maybe a promise if lazy |
| 951 | */ |
| 952 | unpack(reason) { |
| 953 | if (this.content) return; |
| 954 | |
| 955 | const logger = /** @type {Logger} */ (this.logger); |
| 956 | // Move from state B to C |
| 957 | if (this.lazy) { |
| 958 | const { lazyName } = this; |
| 959 | /** @type {string | undefined} */ |
| 960 | let timeMessage; |
| 961 | if (lazyName) { |
| 962 | // only log once |
| 963 | this.lazyName = undefined; |
| 964 | timeMessage = `unpack cache content ${lazyName} (${formatSize( |
| 965 | this.getSize() |
| 966 | )})`; |
| 967 | logger.log( |
| 968 | `starting to unpack cache content ${lazyName} (${formatSize( |
| 969 | this.getSize() |
| 970 | )}) because ${reason}` |
| 971 | ); |
| 972 | logger.time(timeMessage); |
| 973 | } |
| 974 | const value = |
| 975 | /** @type {PackContentItems | Promise<PackContentItems>} */ |
| 976 | (this.lazy()); |
| 977 | if ("then" in value) { |
| 978 | return value.then((data) => { |
| 979 | if (timeMessage) { |
| 980 | logger.timeEnd(timeMessage); |
| 981 | } |
| 982 | this.content = data.map; |
| 983 | }); |
| 984 | } |
| 985 | if (timeMessage) { |
| 986 | logger.timeEnd(timeMessage); |
| 987 | } |
| 988 | this.content = value.map; |
| 989 | } |
| 990 | } |
| 991 | |
| 992 | /** |
| 993 | * Returns the estimated size for the requested source type. |
no test coverage detected