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).

1  
!7
2  
3  
html {
4  
  if (eq(uri, "/worker.js"))
5  
    ret [[
6  
      postMessage("WORKING! Watch your CPU.");
7  
      var startTime = new Date();
8  
      var start = 0, i = start;
9  
      while (true) {
10  
        for (j = 0; j < 1000; j++) {}
11  
        i = i+1;
12  
        if ((i % 1000) == 0) {
13  
          var ms = new Date()-startTime;
14  
          var mips = ((i-start)/ms).toFixed(2);
15  
          postMessage("Counted to: " + i + " in " + ms + " ms ("
16  
            + mips + " million steps/s)");
17  
        }
18  
      }
19  
    ]];
20  
    
21  
  ret htitle("Web Worker Test")
22  
    + hbody(
23  
      p("Count numbers: " + hfulltag("output", "", id := "result"))
24  
    + p(hbutton("Restart Worker", onClick := "restart()"))
25  
  + hjavascript([[
26  
    var worker;
27  
    
28  
    function restart() {
29  
      worker.terminate();
30  
      go();
31  
    }
32  
    
33  
    function go() {
34  
      if (typeof(Worker) === "undefined") {
35  
        document.getElementById("result").innerHTML = "Sorry, your browser does not support Web Workers...";
36  
        return;
37  
      }
38  
      document.getElementById("result").innerHTML = "Making web worker";
39  
      worker = new Worker($LINK);
40  
      worker.onmessage = function(event) {
41  
        document.getElementById("result").innerHTML = event.data;
42  
      };
43  
      //document.getElementById("result").innerHTML = "Worker made, starting";
44  
      //worker.postMessage();
45  
    }
46  
  ]]).replace("$LINK", jsQuote(relativeRawBotLink(programID(), "worker.js"))), onLoad := "go()");
47  
}

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: 619 / 1334
Version history: 17 change(s)
Referenced in: [show references]