Observed - Error: Timeout: Did not receive an init message from worker after 10000ms. Make sure the worker calls expose()

Viewed 173

I have below code in the Index.js file

 try {
        pool = Pool(() => spawn(new Worker('./SubFlows')), workers);
        for (let i = 0; i < dataset.length; i += 1) {
            const task = pool.queue(async (subFlows) => {
                await subFlows(dataset[i], i);
            });
            myTasks.push(task);
        }
    } catch (err) {
        throw err;
    } finally {
        await Promise.allSettled(myTasks);
        await pool.completed(true);
        await pool.terminate(true);
    }

SubFlows.js:

async function subFlows(data, threadId) {
   
    try {
        //business logic goes here.
    }
    catch (e) {
       throw e;
    }
}
expose(subFlows);

The above code is inconsistent and some time its executing fine based on the "dataset.length" but most of time it throws bellow error message.

C:\Users\achu\Documents\New_folder\firetv\framework-v3.0\node_modules\observable-fns\dist\observable.js:42
        setTimeout(() => { throw error; }, 0);
                           ^

Error: Timeout: Did not receive an init message from worker after 10000ms. Make sure the worker calls expose().
    at Timeout._onTimeout (C:\Users\achu\Documents\New_folder\firetv\framework-v3.0\node_modules\threads\dist\master\spawn.js:35:53)
    at listOnTimeout (internal/timers.js:557:17)
    at processTimers (internal/timers.js:500:7)

Can someone help me to resolve this error message

0 Answers
Related