GoogleChromeLabs / comlink-loader

Webpack loader to offload modules to Worker threads seamlessly using Comlink.
https://npm.im/comlink-loader
Apache License 2.0
620 stars 40 forks source link

Error: rawValue is undefined in comlink-loader #23

Open rezaerami opened 4 years ago

rezaerami commented 4 years ago

hello everyone. I'm using the comlink-loader in ReactJS to load a class and call a function in off-thread. it's a very basic function, only returns the given value (I'm gonna use it later to call API in off-thread), but I'm getting this error: Error: rawValue is undefined

here is my worker:

`//@todo: use writelog later to call API // import { writeLog } from 'constants/Helpers/logHelpers';

export class LogWorker { // offThreadLog: payload => writeLog(payload), async offThreadLog(payload) { return payload; } }`

and this is how I loaded and called it

`//some imports import LogWorker from 'comlink-loader!constants/Workers/log.worker'; // some other imports

const Hoc = () => { useEffect(() => { const logWorker = new LogWorker(); window.addEventListener('click', async () => { const response = await logWorker.offThreadLog({ medium: 'HOC', detail: 'off thread log', action: 'click', }); console.log(response); }); }, []); }

export default Hoc;` I also tried the example in docs, but the same error happened. thanks.

rezaerami commented 4 years ago

I also should add when I use anormal function it works whti no problem instead of using class i used below code. export const offThreadLog = payload => { return payload; }