Skip to content

Instantly share code, notes, and snippets.

@developit
Created December 20, 2019 21:55
Show Gist options
  • Save developit/551a9d19b58d7d6169cfae2c008586e0 to your computer and use it in GitHub Desktop.
Save developit/551a9d19b58d7d6169cfae2c008586e0 to your computer and use it in GitHub Desktop.
import { wrap, expose } from 'https://unpkg.com/[email protected]/dist/esm/comlink.mjs';
export default name => wrap(new Worker(import.meta.url, { env:{name}, type:'module' }));
if (process.env.name && !self.document) {
const q = []; onmessage = q.push.bind(q);
import(process.env.name).then(expose).then(() => onmessage = q.map(dispatchEvent))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment