mirror of
https://git.um-react.app/um/um-react.git
synced 2025-11-28 11:33:02 +00:00
Dependency upgrade + lib_um_crypto_rust (#78)
Co-authored-by: 鲁树人 <lu.shuren@um-react.app> Co-committed-by: 鲁树人 <lu.shuren@um-react.app>
This commit is contained in:
17
src/decrypt-worker/util/wasmClass.ts
Normal file
17
src/decrypt-worker/util/wasmClass.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { isPromise } from 'radash';
|
||||
|
||||
export function withWasmClass<T extends { free: () => void }, R>(instance: T, cb: (inst: T) => R): R {
|
||||
let isAsync = false;
|
||||
try {
|
||||
const resp = cb(instance);
|
||||
if (resp && isPromise(resp)) {
|
||||
isAsync = true;
|
||||
resp.finally(() => instance.free());
|
||||
}
|
||||
return resp;
|
||||
} finally {
|
||||
if (!isAsync) {
|
||||
instance.free();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user