MCPcopy Index your code
hub / github.com/tensorflow/tfjs / executeInWorker

Function executeInWorker

e2e/integration_tests/custom_bundle_test.ts:314–340  ·  view source on GitHub ↗

* Helper function for executing scripts in a webworker. We use * webworkers to get isolated contexts for tests for custom bundles. * * @param programUrl url to script to run in worker * @param debug debug mode

(
    programUrl: string, opts: {debug?: boolean, workerParams?: {}})

Source from the content-addressed store, hash-verified

312 * @param debug debug mode
313 */
314async function executeInWorker(
315 programUrl: string, opts: {debug?: boolean, workerParams?: {}}) {
316 return new Promise((resolve, reject) => {
317 const debug = opts.debug || false;
318 const workerParams = opts.workerParams || {};
319 const worker = new Worker(programUrl);
320
321 worker.addEventListener('message', (evt) => {
322 if (evt.data.error) {
323 reject(evt.data.payload);
324 }
325
326 if (debug && evt.data.msg) {
327 console.log('msg from worker: ', evt.data);
328 }
329
330 if (evt.data.result) {
331 if (debug) {
332 console.log('result from worker: ', evt.data.result);
333 }
334 resolve(evt.data.payload);
335 }
336 }, false);
337
338 worker.postMessage(workerParams); // Send data to our worker.
339 });
340}

Callers 1

Calls 1

logMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…