Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
capkverna opened this issue Dec 19, 2019 · 0 comments

Comments

@capkverna
Copy link

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant