Skip to content

A tiny shim for WebWorker (data URI only) that works in Node.

License

Notifications You must be signed in to change notification settings

fabiospampinato/webworker-shim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WebWorker Shim

A tiny shim for WebWorker (data URI only) that works in Node.

Install

npm install --save webworker-shim

Usage

Only WebWorkers encoded as a data:text/javascript;charset=utf-8,* string are supported.

import WebWorker from 'webworker-shim';

const worker = new Worker ( `data:text/javascript;charset=utf-8,${encodeURIComponent (`
  addEventListener ( 'message', event => {
    if ( event.data === 'ping' ) {
      postMessage ( 'pong' );
    }
  });
`)}`);

worker.addEventListener ( 'message', event => {
  console.log ( event.data ); // => 'pong'
});

worker.postMessage ( 'ping' );

License

MIT © Fabio Spampinato