Prevent ResourceManager test failures due to unhandled rejection… (#2812)

* fix: prevent ResourceManager test failures due to unhandled rejection
This commit is contained in:
luzhuang
2025-09-05 16:09:00 +08:00
committed by GitHub
parent bf7da35945
commit 9364b2fd4a
2 changed files with 23 additions and 9 deletions

View File

@@ -209,13 +209,23 @@ export class AssetPromise<T> implements PromiseLike<T> {
}
/**
* Attaches a callback that is invoked when the Promise is settled (fulfilled or rejected). The
* resolved value cannot be modified from the callback.
* @param onfinally The callback to execute when the Promise is settled (fulfilled or rejected).
* @returns A Promise for the completion of the callback.
* Attaches a callback that is invoked when the Promise is settled (fulfilled or rejected).
* The callback result is ignored and the original value/reason is preserved per Promise spec.
* Returns an AssetPromise to keep chainability with AssetPromise methods.
* @param onFinally - The callback to execute when the Promise is settled.
* @returns An AssetPromise for the completion of the callback.
*/
finally(onFinally?: () => void): Promise<T> {
return this._promise.finally(onFinally);
finally(onFinally?: () => void): AssetPromise<T> {
return this.then(
(value) => {
onFinally?.();
return value;
},
(reason) => {
onFinally?.();
throw reason;
}
);
}
/**

View File

@@ -158,9 +158,13 @@ export class GLTFParserContext {
_addTaskCompletePromise(taskPromise: AssetPromise<any>): void {
const task = this._progress.taskComplete;
task.total += 1;
taskPromise.finally(() => {
this._setTaskCompleteProgress(++task.loaded, task.total);
});
taskPromise
.finally(() => {
this._setTaskCompleteProgress(++task.loaded, task.total);
})
.catch((e) => {
// Need catch to avoid unhandled rejection
});
}
private _handleSubAsset<T>(