js/j15worker.php
<html>
<head>
<title> <?php echo basename(__file__, '.php'); ?> </title>
<script type="text/javascript">
const loopLimit = 3e9
let checkAliveVal = 0, worker;
function checkAlive() {
const bCheckAlive = document.getElementById('iCheckAlive');
bCheckAlive.value = 'check Alive ' + ++checkAliveVal;
}
function workerSt() {
const tWo = document.getElementById('tWo');
if (worker !== undefined)
return tWo.innerHTML = 'already started'
try {
worker = new Worker('j15workerWor3.js')
worker.onmessage = (e) => {
const d = e.data
let m = "main onmessage: " + e
for (const n in d)
m += ` ${n}: ${d[n]}`
document.getElementById('r3').innerHTML = document.getElementById('r2').innerHTML;
document.getElementById('r2').innerHTML = document.getElementById('r1').innerHTML;
document.getElementById('r1').innerHTML = m
if (d.cat === 'startup')
tWo.innerHTML = 'worker started ' + worker;
else if (d.cat === 'loop')
document.getElementById('iLo').value = d.txt
}
tWo.innerHTML = 'worker starting ' + worker;
document.getElementById('iTe').value = 'worker terminate'
} catch (e) {
tWo.innerHTML = 'starting worker catch error ' + e + ', worker '+ worker;
}
worker.onerror = (e) => tWo.value += ' worker.onerror: ' + e + ': ' + e.type + ' ' + e.toString()
setTimeout( () => worker.postMessage({cat: 'startup', typ: 'msg'}), 2000)
}
function workerTe() {
const tWo = document.getElementById('tWo');
try {
worker.terminate()
tWo.innerHTML = 'worker terminated';
worker = undefined
} catch (e) {
tWo.innerHTML = 'worker terminate error ' + e;
}
}
function workerLo() {
document.getElementById('iLo').value = 'worker looping'
worker.postMessage({cat: 'loop', typ: 'msg'})
}
function workerHa() {
document.getElementById('iHa').value = 'Hamilton starting'
worker.postMessage({cat: 'hamilton', typ: 'msg'})
}
function workerH32() {
document.getElementById('iH32').value = 'Hamilto32 starting'
worker.postMessage({cat: 'hamilto32', typ: 'msg'})
}
function workerH2() {
document.getElementById('iH2').value = 'Hamilto2 starting'
worker.postMessage({cat: 'hamilto2', typ: 'msg'})
}
</script>
</head>
<body>
<h1 >check it</h1>
<ul>
<li><input id='iCheckAlive' type="button" value="check Alive" onclick='checkAlive()'/> click here to see, if the window is responsive</li>
<li><input type="button" value="start worker" onclick='workerSt()'/> <input id='iTe' type="button" value="worker terminate" onclick='workerTe()'/> <span id='tWo'></span></li>
<li><input id='iLo' type="button" value="worker loop" onclick='workerLo()'/> loop with progress messages</li>
<li><input id='iHa' type="button" value="Springer Hamilton Path" onclick='workerHa()'/>Hamilton Path - Springer auf Schachbrett</li>
<li><input id='iH32' type="button" value="Springer/32 Hamilton Path" onclick='workerH32()'/>Hamilton Path - Springer 32 Sprünge in 32bit Logic - punktsymmetrisch frei für nächste 32</li>
<li><input id='iH2' type="button" value="Springer/2 Hamilton Path" onclick='workerH2()'/>Hamilton Path - Springer 32 Sprünge - punktsymmetrisch frei für nächste 32</li>
<li>Hamilton Path - Springer auf 1/4 Schachbrett Rotation geht nicht</li>
<li>response from worker<ol>
<li id=r1></li>
<li id=r2></li>
<li id=r3></li>
</ol>
</ul>
<h1 id="src">Source <?php echo __file__; ?> </h1>
<?php highlight_file(__file__) ?>
</body>
</html>