UNPKG

@puzzlehq/aleo-wasm-nodejs

Version:

Aleo SDK WASM for Node.js

42 lines (35 loc) 1.27 kB
export function spawnWorker(url, module, memory, address) { return new Promise((resolve) => { const worker = new Worker(url, { type: "module", }); worker.addEventListener("message", (event) => { // This is needed in Node to wait one extra tick, so that way // the Worker can fully initialize before we return. setTimeout(() => { resolve(worker); // When running in Node, this allows the process to exit // even though the Worker is still running. if (worker.unref) { worker.unref(); } }, 0); }, { capture: true, once: true, }); worker.postMessage({ module, memory, address, }); }); } export function startTimer() { // Starts a super-long timer in order to keep the Node // process alive until we manually cancel it. return setTimeout(() => {}, Math.pow(2, 31) - 1); } export function stopTimer(timer) { clearTimeout(timer); }