* Processes the provided write. * @param {(lazy: LazyFunction) => (() => PackContentItems | Promise<PackContentItems>)} write write function * @returns {void}
(write)
| 1020 | * @returns {void} |
| 1021 | */ |
| 1022 | writeLazy(write) { |
| 1023 | if (!this.outdated && this.lazy) { |
| 1024 | // State B1 or C1 |
| 1025 | // this.lazy is still the valid deserialized version |
| 1026 | write(this.lazy); |
| 1027 | return; |
| 1028 | } |
| 1029 | if (!this.outdated && this.content) { |
| 1030 | // State A1 |
| 1031 | const map = new Map(this.content); |
| 1032 | // Move to state C1 |
| 1033 | this.lazy = SerializerMiddleware.unMemoizeLazy( |
| 1034 | write(() => new PackContentItems(map)) |
| 1035 | ); |
| 1036 | return; |
| 1037 | } |
| 1038 | if (this.content) { |
| 1039 | // State A2 or C2 |
| 1040 | /** @type {Content} */ |
| 1041 | const map = new Map(); |
| 1042 | for (const item of this.items) { |
| 1043 | map.set(item, this.content.get(item)); |
| 1044 | } |
| 1045 | // Move to state C1 |
| 1046 | this.outdated = false; |
| 1047 | this.content = map; |
| 1048 | this.lazy = SerializerMiddleware.unMemoizeLazy( |
| 1049 | write(() => new PackContentItems(map)) |
| 1050 | ); |
| 1051 | return; |
| 1052 | } |
| 1053 | const logger = /** @type {Logger} */ (this.logger); |
| 1054 | // State B2 |
| 1055 | const { lazyName } = this; |
| 1056 | /** @type {string | undefined} */ |
| 1057 | let timeMessage; |
| 1058 | if (lazyName) { |
| 1059 | // only log once |
| 1060 | this.lazyName = undefined; |
| 1061 | timeMessage = `unpack cache content ${lazyName} (${formatSize( |
| 1062 | this.getSize() |
| 1063 | )})`; |
| 1064 | logger.log( |
| 1065 | `starting to unpack cache content ${lazyName} (${formatSize( |
| 1066 | this.getSize() |
| 1067 | )}) because it's outdated and need to be serialized` |
| 1068 | ); |
| 1069 | logger.time(timeMessage); |
| 1070 | } |
| 1071 | const value = /** @type {LazyFunction} */ (this.lazy)(); |
| 1072 | this.outdated = false; |
| 1073 | if ("then" in value) { |
| 1074 | // Move to state B1 |
| 1075 | this.lazy = write(() => |
| 1076 | value.then((data) => { |
| 1077 | if (timeMessage) { |
| 1078 | logger.timeEnd(timeMessage); |
| 1079 | } |
no test coverage detected