Skip to content

Commit fdab81a

Browse files
The unload method will always return a promise
1 parent 671bfc6 commit fdab81a

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

module/source/hooks/use-unity-context.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,20 @@ const useUnityContext = (unityConfig: IUnityConfig): IUnityContextHook => {
138138
* Requests the UnityInstance to be unloaded from memory in order to be
139139
* unmounted from the DOM.
140140
*/
141-
const unload = useCallback((): Promise<void> | undefined => {
142-
if (unityInstance === null) {
143-
// Guarding the Unity Instance.
144-
console.warn(errorMessages.quitNoUnityInstance);
145-
return;
146-
}
147-
return unityInstance.Quit();
148-
}, [unityInstance]);
141+
const unload = useCallback(
142+
/**
143+
* @returns A promise that resolves when the UnityInstance has been unloaded.
144+
*/
145+
(): Promise<void> => {
146+
if (unityInstance === null) {
147+
// Guarding the Unity Instance.
148+
console.warn(errorMessages.quitNoUnityInstance);
149+
return Promise.reject();
150+
}
151+
return unityInstance.Quit();
152+
},
153+
[unityInstance]
154+
);
149155

150156
// Effect invoked when the loading progression changes. When the loading
151157
// progression is equal to or more than 1, the Unity Instance is considered

module/source/interfaces/unity-context-hook.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,9 @@ interface IUnityContextHook extends IEventSystemHook {
7070
/**
7171
* Requests the UnityInstance to be unloaded from memory in order to be
7272
* unmounted from the DOM.
73+
* @returns A promise that resolves when the UnityInstance has been unloaded.
7374
*/
74-
readonly unload: () => Promise<void> | undefined;
75+
readonly unload: () => Promise<void>;
7576
}
7677

7778
export type { IUnityContextHook };

0 commit comments

Comments
 (0)