From 72c1d2bdfeaedd72bb30759cf58fc8dce3532ddd Mon Sep 17 00:00:00 2001 From: jakmro Date: Tue, 17 Jun 2025 11:51:53 +0200 Subject: [PATCH] fix: move try/catch inside async function, delete model when preventLoad==false --- .../natural_language_processing/useLLM.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/react-native-executorch/src/hooks/natural_language_processing/useLLM.ts b/packages/react-native-executorch/src/hooks/natural_language_processing/useLLM.ts index f00927d6c7..5f861c033b 100644 --- a/packages/react-native-executorch/src/hooks/natural_language_processing/useLLM.ts +++ b/packages/react-native-executorch/src/hooks/natural_language_processing/useLLM.ts @@ -46,19 +46,19 @@ export const useLLM = ({ setDownloadProgress(0); setError(null); - if (!preventLoad) { + if (preventLoad) return; + + (async () => { try { - (async () => { - await model.load({ - modelSource, - tokenizerSource, - tokenizerConfigSource, - }); - })(); + await model.load({ + modelSource, + tokenizerSource, + tokenizerConfigSource, + }); } catch (e) { setError(e); } - } + })(); return () => { model.delete();