"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getInstance = exports.init = void 0;
const onnxruntime_wasm_1 = __importDefault(require("./onnxruntime_wasm"));
// some global parameters to deal with wasm binding initialization
let wasm;
let initialized = false;
let initializing = false;
/**
 * initialize the WASM instance.
 *
 * this function should be called before any other calls to the WASM binding.
 */
const init = async () => {
    if (initialized) {
        return Promise.resolve();
    }
    if (initializing) {
        throw new Error('multiple calls to \'init()\' detected.');
    }
    initializing = true;
    return new Promise((resolve, reject) => {
        onnxruntime_wasm_1.default().then(initializedModule => {
            // resolve init() promise
            wasm = initializedModule;
            initializing = false;
            initialized = true;
            resolve();
        }, err => {
            initializing = false;
            reject(err);
        });
    });
};
exports.init = init;
const getInstance = () => wasm;
exports.getInstance = getInstance;
//# sourceMappingURL=index.js.map