mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-05-26 22:35:43 +00:00
* add web * add script and test * fix lint * add test/data/ops * add test/data/node/ to gitignore * modify scripts * add onnxjs * fix tests * fix test-runner * fix sourcemap * fix onnxjs profiling * update test list * update README * resolve comments * set wasm as default backend * rename package * update copyright header * do not use class "Buffer" in browser context * revise readme
42 lines
1.1 KiB
TypeScript
42 lines
1.1 KiB
TypeScript
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
// Licensed under the MIT License.
|
|
|
|
import wasmModuleFactory, {BackendWasmModule} from './onnxruntime_wasm';
|
|
|
|
// some global parameters to deal with wasm binding initialization
|
|
let wasm: BackendWasmModule;
|
|
let initialized = false;
|
|
let initializing = false;
|
|
|
|
/**
|
|
* initialize the WASM instance.
|
|
*
|
|
* this function should be called before any other calls to the WASM binding.
|
|
*/
|
|
export const init = async(): Promise<void> => {
|
|
if (initialized) {
|
|
return Promise.resolve();
|
|
}
|
|
if (initializing) {
|
|
throw new Error('multiple calls to \'init()\' detected.');
|
|
}
|
|
|
|
initializing = true;
|
|
|
|
return new Promise<void>((resolve, reject) => {
|
|
wasmModuleFactory().then(
|
|
initializedModule => {
|
|
// resolve init() promise
|
|
wasm = initializedModule;
|
|
initializing = false;
|
|
initialized = true;
|
|
resolve();
|
|
},
|
|
err => {
|
|
initializing = false;
|
|
reject(err);
|
|
});
|
|
});
|
|
};
|
|
|
|
export const getInstance = (): BackendWasmModule => wasm;
|