worker.js 859 B

12345678910111213141516171819202122232425262728293031
  1. self.addEventListener('message', function (e) {
  2. if (e.data.type === 'request-start-msr-loop') {
  3. if (e.data.delay > 0) {
  4. const timer = setInterval(function () {
  5. self.postMessage({
  6. type: 'response-msr-looping',
  7. data: { timer },
  8. });
  9. }, e.data.delay);
  10. self.postMessage({
  11. type: 'response-start-msr-loop',
  12. data: { timer },
  13. });
  14. }
  15. } else if (e.data.type === 'request-start-loop') {
  16. if (e.data.delay > 0) {
  17. const timer = setInterval(function () {
  18. self.postMessage({
  19. type: 'response-looping',
  20. data: { timer },
  21. });
  22. }, e.data.delay);
  23. self.postMessage({
  24. type: 'response-start-loop',
  25. data: { timer },
  26. });
  27. }
  28. } else if (e.data.type === 'request-clear-loop') {
  29. clearInterval(e.data.timer);
  30. }
  31. });