* Load each task in order.
()
| 1055 | * Load each task in order. |
| 1056 | */ |
| 1057 | async loadAllTasksInBackground(): Promise<void> { |
| 1058 | if (this.currentLoadingTaskIdentifier) { |
| 1059 | return; |
| 1060 | } |
| 1061 | |
| 1062 | debugLogger.log(`Loading all ${this.name} resources, in background.`); |
| 1063 | while (this.loadingTaskQueue.length > 0) { |
| 1064 | debugLogger.log( |
| 1065 | `Still resources of ${this.loadingTaskQueue.length} ${this.name}(s) to load: ${this.loadingTaskQueue.map((task) => task.identifier).join(', ')}` |
| 1066 | ); |
| 1067 | const task = this.loadingTaskQueue[this.loadingTaskQueue.length - 1]; |
| 1068 | if (task === undefined) { |
| 1069 | continue; |
| 1070 | } |
| 1071 | this.currentLoadingTaskIdentifier = task.identifier; |
| 1072 | if (!this.areAssetsLoaded(task.identifier)) { |
| 1073 | debugLogger.log( |
| 1074 | `Loading (but not processing) resources for ${this.name} ${task.identifier}.` |
| 1075 | ); |
| 1076 | const loadingState = this.loadingStates.get(task.identifier); |
| 1077 | if (loadingState) { |
| 1078 | await this._doLoadResources(loadingState, async (count, total) => |
| 1079 | task.onProgress(count, total) |
| 1080 | ); |
| 1081 | } else { |
| 1082 | logger.warn( |
| 1083 | `Can\'t load resource for unknown ${this.name}: "${task.identifier}".` |
| 1084 | ); |
| 1085 | return; |
| 1086 | } |
| 1087 | debugLogger.log( |
| 1088 | `Done loading (but not processing) resources for ${this.name} ${task.identifier}.` |
| 1089 | ); |
| 1090 | |
| 1091 | // A task may have been moved last while awaiting resources to be |
| 1092 | // downloaded (see _prioritize). |
| 1093 | this.loadingTaskQueue.splice( |
| 1094 | this.loadingTaskQueue.findIndex((element) => element === task), |
| 1095 | 1 |
| 1096 | ); |
| 1097 | task.onFinish(); |
| 1098 | } else { |
| 1099 | this.loadingTaskQueue.pop(); |
| 1100 | } |
| 1101 | } |
| 1102 | debugLogger.log(`${this.name} resources loading finished.`); |
| 1103 | this.currentLoadingTaskIdentifier = ''; |
| 1104 | } |
| 1105 | |
| 1106 | private async _doLoadResources( |
| 1107 | loadingState: LoadingTaskState, |
no test coverage detected