 onmessage = function (e:MessageEvent) {
     const result = e.data;
     if (result === 'heartbeat') {
         heartbeat()
     }
     console.log('Worker: Message received from main script',result);
}

const heartbeat = () => {
    setInterval(() => {
        postMessage('heartbeat')
    },4000)
}