1
0
Fork 0
mirror of https://github.com/codedread/bitjs synced 2025-10-05 10:29:24 +02:00

For issue #44, make the Zipper use MessageChannel and not have a hard dependency on Worker

This commit is contained in:
Jeff Schiller 2023-12-13 12:40:45 -08:00
parent eeb228a52b
commit 48766d0136
5 changed files with 116 additions and 81 deletions

View file

@ -0,0 +1,21 @@
/**
* webworker-wrapper.js
*
* Licensed under the MIT License
*
* Copyright(c) 2023 Google Inc.
*/
/**
* A WebWorker wrapper for a decompress/compress implementation. Upon creation and being sent its
* first message, it dynamically imports the decompressor / compressor implementation and connects
* the message port. All other communication takes place over the MessageChannel.
*/
/** @type {MessagePort} */
let implPort;
onmessage = async (evt) => {
const module = await import(evt.data.implSrc);
module.connect(evt.ports[0]);
};