function initWorker(pathPrefix) {
    pathPrefix = pathPrefix || getPathPrefix();

    if (typeof workerPromise === 'undefined') {
        workerPromise = new Promise(function (resolve, reject) {
            let _worker = new Worker(pathPrefix + 'loam-worker.js');

            // The worker needs to do some initialization, and will send a message when it's ready.
            _worker.onmessage = function (msg) {
                if (msg.data.ready) {
                    // Once the worker's ready, change the onMessage function to execute and clear
                    // the stored promise resolvers.
                    _worker.onmessage = function (msg) {
                        // Execute stored promise resolver by message ID
                        // Promise resolvers are stored by callWorker().
                        if (msg.data.success) {
                            messages[msg.data.id][0](msg.data.result);
                        } else {
                            messages[msg.data.id][1](new Error(msg.data.message));
                        }
                        delete messages[msg.data.id];
                    };
                    resolve(_worker);
                } else if (msg.data.error) {
                    reject(msg.data.error);
                }
            };
        });
    }
    return workerPromise;
}
// Set up a WebWorker and an associated promise that resolves once it's ready
Set up a WebWorker and an associated promise that resolves once it's ready
Set up a WebWorker and an associated promise that resolves once it ' s ready
function initWorker(pathPrefix) {
    pathPrefix = pathPrefix || getPathPrefix();
    if (typeof workerPromise === 'undefined') {
        workerPromise = new Promise(function (resolve, reject) {
            let _worker = new Worker(pathPrefix + 'loam-worker.js');
            _worker.onmessage = function (msg) {
                if (msg.data.ready) {
                    _worker.onmessage = function (msg) {
                        if (msg.data.success) {
                            messages[msg.data.id][0](msg.data.result);
                        } else {
                            messages[msg.data.id][1](new Error(msg.data.message));
                        }
                        delete messages[msg.data.id];
                    };
                    resolve(_worker);
                } else if (msg.data.error) {
                    reject(msg.data.error);
                }
            };
        });
    }
    return workerPromise;
}
function initWorker ( pathPrefix ) { pathPrefix = pathPrefix || getPathPrefix ( ) ; if ( typeof workerPromise === 'undefined' ) { workerPromise = new Promise ( function ( resolve , reject ) { let _worker = new Worker ( pathPrefix + 'loam-worker.js' ) ; _worker . onmessage = function ( msg ) { if ( msg . data . ready ) { _worker . onmessage = function ( msg ) { if ( msg . data . success ) { messages [ msg . data . id ] [ 0 ] ( msg . data . result ) ; } else { messages [ msg . data . id ] [ 1 ] ( new Error ( msg . data . message ) ) ; } delete messages [ msg . data . id ] ; } ; resolve ( _worker ) ; } else if ( msg . data . error ) { reject ( msg . data . error ) ; } } ; } ) ; } return workerPromise ; }
Set up a WebWorker and an associated promise that resolves once it's ready
Set up a WebWorker and an associated promise that resolves once it ' s ready
// The worker needs to do some initialization, and will send a message when it's ready. // Once the worker's ready, change the onMessage function to execute and clear // the stored promise resolvers. // Execute stored promise resolver by message ID // Promise resolvers are stored by callWorker().