ngx-web-worker icon indicating copy to clipboard operation
ngx-web-worker copied to clipboard

Error trying to use the webworker with a function that returns a promise

Open capkverna opened this issue 6 years ago • 0 comments

Hello, I need to use the webworker to run a function that communicates with a rest api. I tried some ways, but its not working. That's what i tried:

this._webWorkerService.run(this.searchNotifications, params).then((retorno: any) => { console.log('retorno', retorno); this._webWorkerService.terminate(); });

searchNotifications(params: any) { return new Promise((resolve, reject) => { let xhr = new XMLHttpRequest(); xhr.open('POST', params.url);
xhr.setRequestHeader('Content-Type', 'application/json'); xhr.setRequestHeader('Accept', 'application/json'); xhr.setRequestHeader('Authorization', 'Bearer ' + params.tokenAuthorization); xhr.onload = () => { resolve(xhr.response); }; xhr.onerror = () => { reject(xhr.response); }; xhr.send(JSON.stringify(params.filter)); }); }

And that's the error:

core.js:15724 ERROR Error: Uncaught (in promise): ErrorEvent: {"isTrusted":true} at resolvePromise (zone.js:814) at resolvePromise (zone.js:771) at zone.js:873 at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:421) at Object.onInvokeTask (core.js:17290) at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:420) at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (zone.js:188) at drainMicroTaskQueue (zone.js:595) at ZoneTask.push../node_modules/zone.js/dist/zone.js.ZoneTask.invokeTask [as invoke] (zone.js:500) at invokeTask (zone.js:1540)

capkverna avatar Dec 19 '19 11:12 capkverna