Download Jar. Libraryless. Click here for Pure Java version (1857L/12K/43K).
1 | !7 |
2 | |
3 | html { |
4 | if (eq(uri, "/worker.js")) |
5 | ret [[ |
6 | postMessage("WORKING!"); |
7 | var startTime = new Date(); |
8 | var i = 0; |
9 | while (true) { |
10 | i = i+1; |
11 | if ((i % 1000000) == 0) { |
12 | var ms = new Date()-startTime; |
13 | var mips = (i/ms/1000).toFixed(2); |
14 | postMessage("Counted to: " + i + " in " + ms + " ms (" |
15 | + mips + " million steps/s)"); |
16 | } |
17 | } |
18 | ]]; |
19 | |
20 | ret htitle("Web Worker Test") |
21 | + hbody( |
22 | p(hfulltag("output", "", id := "result1")) |
23 | + p(hfulltag("output", "", id := "result2")) |
24 | + p(hbutton("Restart Worker", onClick := "restart()")) |
25 | + hjavascript([[ |
26 | var workers = []; |
27 | |
28 | function restart() { |
29 | for (w of workers) { w.terminate(); } |
30 | workers = []; |
31 | go(); |
32 | } |
33 | |
34 | function go() { |
35 | for (i = 1; i <= $WORKERS; i++) go1(i); |
36 | } |
37 | |
38 | function go1(i) { |
39 | var res = document.getElementById("result" + i); |
40 | if (typeof(Worker) === "undefined") { |
41 | res.innerHTML = "Sorry, your browser does not support Web Workers..."; |
42 | return; |
43 | } |
44 | res.innerHTML = "Making web worker"; |
45 | var worker = new Worker($LINK); |
46 | worker.onmessage = function(event) { |
47 | res.innerHTML = event.data; |
48 | }; |
49 | workers.push(worker); |
50 | } |
51 | ]]).replace("$LINK", jsQuote(relativeRawBotLink(programID(), "worker.js"))), onLoad := "go()") |
52 | .replace("$WORKERS", str(2)); |
53 | } |
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: | 540 / 1124 |
Version history: | 4 change(s) |
Referenced in: | [show references] |