Skip to content

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

Description

@capkverna

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)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions