You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

worker.ts 674B

1234567891011121314151617181920212223242526272829
  1. import {
  2. CLEAR_INTERVAL,
  3. INTERVAL_TIMEOUT,
  4. SET_INTERVAL
  5. } from './constants';
  6. const code = `
  7. var timer;
  8. onmessage = function(request) {
  9. switch (request.data.id) {
  10. case ${SET_INTERVAL}: {
  11. timer = setInterval(() => {
  12. postMessage({ id: ${INTERVAL_TIMEOUT} });
  13. }, request.data.timeMs);
  14. break;
  15. }
  16. case ${CLEAR_INTERVAL}: {
  17. if (timer) {
  18. clearInterval(timer);
  19. }
  20. break;
  21. }
  22. }
  23. };
  24. `;
  25. // @ts-ignore
  26. export const timerWorkerScript = URL.createObjectURL(new Blob([ code ], { type: 'application/javascript' }));