🎣 Custom Hooks Meet Web Workers: Transform Your React Apps

Поделиться
HTML-код
  • Опубликовано: 28 ноя 2024

Комментарии • 6

  • @IsraelAgyemanPrempeh
    @IsraelAgyemanPrempeh 4 месяца назад

    Cool, I like the your alternative implementation of ‘eval’ in JavaScript with blobs

  • @Wakkyguy
    @Wakkyguy 8 месяцев назад +1

    Unable to use any other function inside the worker function even when it is in the same module.
    /* eslint-disable no-restricted-globals */
    export function heavyCalc() {
    for (let i = 0; i < 1_000_000_000; i++) {}
    }
    export function workerizedFib() {
    self.onmessage = function (e) {
    console.log('Data from parent:', e.data);
    heavyCalc();
    self.postMessage('Message from worker function');
    };
    }
    Uncaught ReferenceError: heavyCalc is not defined.
    Please advise.

    • @-n9052
      @-n9052 8 месяцев назад

      Me too. Did you solve it?😣

    • @Wakkyguy
      @Wakkyguy 8 месяцев назад

      @@-n9052 nope

    • @testmail3875
      @testmail3875 7 месяцев назад +1

      when using Web Workers, the script is executed in a separate global scope, which means it doesn't have access to functions or variables defined in the main thread.
      importScripts('path/to/your/module.js'); // heavyCalc() should be there
      self.onmessage = function (e) {
      console.log('Data from parent:', e.data);
      heavyCalc();
      self.postMessage('Message from worker function');
      };

  • @0xtz_
    @0xtz_ 6 месяцев назад

    cool 😎