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

47
LINES

< > BotCompany Repo | #1013783 // Web Worker Test

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

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

!7

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

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: #1013783
Snippet name: Web Worker Test
Eternal ID of this version: #1013783/18
Text MD5: 0b8fc834bd0e93f2d178a4438b4ad639
Transpilation MD5: deb33233a51306964fb3eb4d4e9d0986
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 21:33:28
Source code size: 1467 bytes / 47 lines
Pitched / IR pitched: No / No
Views / Downloads: 618 / 1328
Version history: 17 change(s)
Referenced in: [show references]