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.js 670B

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