tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

worker_suspended.js (862B)


      1 var count = 0;
      2 
      3 function do_magic(data) {
      4  caches
      5    .open("test")
      6    .then(function (cache) {
      7      return cache.put(
      8        "http://mochi.test:888/foo",
      9        new Response(data.type + "-" + count++)
     10      );
     11    })
     12    .then(function () {
     13      if (count == 1) {
     14        postMessage("ready");
     15      }
     16 
     17      if (data.loop) {
     18        setTimeout(function () {
     19          do_magic(data);
     20        }, 500);
     21      }
     22    });
     23 }
     24 
     25 onmessage = function (e) {
     26  if (e.data.type == "page1") {
     27    if (e.data.count > 0) {
     28      var a = new Worker("worker_suspended.js");
     29      a.postMessage({ type: "page1", count: e.data - 1 });
     30      a.onmessage = function () {
     31        postMessage("ready");
     32      };
     33    } else {
     34      do_magic({ type: e.data.type, loop: true });
     35    }
     36  } else if (e.data.type == "page2") {
     37    do_magic({ type: e.data.type, loop: false });
     38  }
     39 };