I am calling get API which is taking more than 22s due to some expensive DB query from API. I need to call this api using web worker . Here is my current ngOnInit ngOnInit() { this.fethDetails() } fetchDetails(){ this.serviceName.getList().subscribe({ next: (data) => { this.siteLists = data; }, error: (error) => { console.log(error) }, complete: () => { console.log('complete') } }) } /// <reference lib="webworker" /> addEventListener('message', ({ data }) => { const response = // need to call fetchDetails(); postMessage(response); }); if (typeof Worker !== 'undefined') { // Create a new const worker = new Worker(new URL('./report.worker', import.meta.url)); worker.onmessage = ({ data }) => { console.log(`page got message: ${data}`); }; worker.postMessage('hello'); } else { // Web Workers are not supported in this environment. // You should add a fallback so that your program still executes correctly. } I need to call my fetchDetails() function from worker but not able to call its showing error . addEventListener('message', ({ data }) => { const reportData = // need to call fetchDetails(); //fetchDetails(); postMessage(reportData); }); Continue reading...