Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

53
LINES

< > BotCompany Repo | #1013796 // Parallel Web Worker Test

JavaX module [tags: ai1-lol use-pretranspiled] - homepage

Download Jar. Libraryless. Click here for Pure Java version (1857L/12K/43K).

!7

html {
  if (eq(uri, "/worker.js"))
    ret [[
      postMessage("WORKING!");
      var startTime = new Date();
      var i = 0;
      while (true) {
        i = i+1;
        if ((i % 1000000) == 0) {
          var ms = new Date()-startTime;
          var mips = (i/ms/1000).toFixed(2);
          postMessage("Counted to: " + i + " in " + ms + " ms ("
            + mips + " million steps/s)");
        }
      }
    ]];
    
  ret htitle("Web Worker Test")
    + hbody(
      p(hfulltag("output", "", id := "result1"))
    + p(hfulltag("output", "", id := "result2"))
    + p(hbutton("Restart Worker", onClick := "restart()"))
  + hjavascript([[
    var workers = [];
    
    function restart() {
      for (w of workers) { w.terminate(); }
      workers = [];
      go();
    }
    
    function go() {
      for (i = 1; i <= $WORKERS; i++) go1(i);
    }
     
    function go1(i) { 
      var res = document.getElementById("result" + i);
      if (typeof(Worker) === "undefined") {
        res.innerHTML = "Sorry, your browser does not support Web Workers...";
        return;
      }
      res.innerHTML = "Making web worker";
      var worker = new Worker($LINK);
      worker.onmessage = function(event) {
        res.innerHTML = event.data;
      };
      workers.push(worker);
    }
  ]]).replace("$LINK", jsQuote(relativeRawBotLink(programID(), "worker.js"))), onLoad := "go()")
    .replace("$WORKERS", str(2));
}

Author comment

Began life as a copy of #1013783

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

-
Snippet ID: #1013796
Snippet name: Parallel Web Worker Test
Eternal ID of this version: #1013796/5
Text MD5: fadb1299866e2bb26aad11e25626eeab
Transpilation MD5: 80ad974dd2efeaa47b55e953eaa765af
Author: stefan
Category: javax / web workers
Type: JavaX module
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-02-28 13:45:14
Source code size: 1480 bytes / 53 lines
Pitched / IR pitched: No / No
Views / Downloads: 539 / 1118
Version history: 4 change(s)
Referenced in: