Upgrade dependencies, fix for TypeScript 3.9 while breaking for any older versions of TypeScript.
Switched from Flow to TypeScript, cause momentum. Sadly TypeScript sucks at supporting shared workers, so the typings are a bit worse, but promise-worker-bi works the same.
Split the old PromiseWorker class into two separate classes PWBHost and PWBWorker, so they can be included separately in main and worker bundles, leading to smaller bundle sizes if you use tree shaking and dead code elimination. Savings seems to just be a couple kb of minified JS per bundle, but every byte counts!
This should obviously print "true":
blob = new Blob(["self.onmessage = function() {};"], { type: "text/javascript" });
worker = new Worker(window.URL.createObjectURL(blob));
console.log(worker instanceof Worker);
However in some rare cases, it will print "false" in Safari. This caused bugs in prior versions of promise-worker-bi, but this release includes a workaround.
Restore console.error
logging for errors in the worker, because otherwise it can be difficult to debug live since the errors sent back to the window by promise-worker-bi do not have source maps applied.
v3.0.0 brings better and more consistent error handling!
All errors from workers include the stack
property, and any others (Firefox has some extra non-standard properties). Since normally stack traces are not sent from the worker to the main thread, instead we capture the stack trace in the worker and manually send it to the main thread.
Additionally, the callback passed to PromiseWorker.registerError
will now recieve Error objects directly, rather than ErrorEvent objects or weird non-standard things that are kind of like ErrorEvent objects. This is a breaking change to the API, necessitating the new major version.
Fix race condition where hostID was previously sometimes undefined.
Cross-browser consistency in error reporting from Shared Workers through PromiseWorker.registerError.
When using a Shared Worker, if the user closes a tab, we don't need to keep track of that hostID and MessagePort anymore.
Added support for Shared Workers.
Fix error reporting in Safari.
Fix error reporting.
First release of promise-worker-bi, forked from promise-worker but adding support for sending messages from the worker to the host, rather than just from the host to the worker.