diff --git a/packages/core/src/asset/AssetPromise.ts b/packages/core/src/asset/AssetPromise.ts index 39bf32fc9..99f00e86f 100644 --- a/packages/core/src/asset/AssetPromise.ts +++ b/packages/core/src/asset/AssetPromise.ts @@ -209,13 +209,23 @@ export class AssetPromise implements PromiseLike { } /** - * 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 { - return this._promise.finally(onFinally); + finally(onFinally?: () => void): AssetPromise { + return this.then( + (value) => { + onFinally?.(); + return value; + }, + (reason) => { + onFinally?.(); + throw reason; + } + ); } /** diff --git a/packages/loader/src/gltf/parser/GLTFParserContext.ts b/packages/loader/src/gltf/parser/GLTFParserContext.ts index 78c830da5..83f9f6512 100644 --- a/packages/loader/src/gltf/parser/GLTFParserContext.ts +++ b/packages/loader/src/gltf/parser/GLTFParserContext.ts @@ -158,9 +158,13 @@ export class GLTFParserContext { _addTaskCompletePromise(taskPromise: AssetPromise): 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(