This fixes an issue where it's not possible to use this library inside of a NodeJS worker thread, since the check below is not accounting for where the thread originated from. When using this library within a worker thread, the workerThread() code is executed, rather than the mainThread() code which creates the worker polyfill.
This change executes workerThread() only if the mod property is present from the workerData, indicating that it's being executed from a thread created within this library. If mod isn't present, this means that the code is executing within the context of some other worker thread that wasn't created from this library, and it needs to treat the current thread as the main thread by executing mainThread().
One enhancement might be to randomize the mod property name. This change assumes that a parent thread won't send a mod property in the workerData...
Hi @eshaz - any update on merging this? Would this also address #42? This should also be updated in your other package https://github.com/eshaz/wasm-audio-decoders which is using this as a dependency.
This fixes an issue where it's not possible to use this library inside of a NodeJS worker thread, since the check below is not accounting for where the thread originated from. When using this library within a worker thread, the
workerThread()
code is executed, rather than themainThread()
code which creates the worker polyfill.https://github.com/developit/web-worker/blob/29fef9775702c91887d3d8733e595edf1a188f31/node.js#L73
This change executes
workerThread()
only if themod
property is present from theworkerData
, indicating that it's being executed from a thread created within this library. Ifmod
isn't present, this means that the code is executing within the context of some other worker thread that wasn't created from this library, and it needs to treat the current thread as the main thread by executingmainThread()
.One enhancement might be to randomize the
mod
property name. This change assumes that a parent thread won't send amod
property in theworkerData
...