1
0
Fork 0
mirror of https://github.com/codedread/bitjs synced 2025-10-03 17:49:16 +02:00
bitjs/archive/webworker-wrapper.js

25 lines
644 B
JavaScript

/**
* 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) => {
if (evt.data.implSrc) {
const module = await import(evt.data.implSrc);
module.connect(evt.ports[0]);
} else if (evt.data.disconnect) {
module.disconnect();
}
};