Fix logic error resulting in numbers setting not being observed

This commit is contained in:
RunasSudo 2020-10-18 02:55:15 +11:00
parent 93f0100856
commit 07afc233b4
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
2 changed files with 18 additions and 11 deletions

View File

@ -42,14 +42,6 @@
<script> <script>
async function clickBtn() { async function clickBtn() {
// Set numbers class
if (document.getElementById('numbers').value == 'native') {
py.pyRCV2.numbers.set_numclass(py.pyRCV2.numbers.Native);
}
if (document.getElementById('numbers').value == 'rational') {
py.pyRCV2.numbers.set_numclass(py.pyRCV2.numbers.Rational);
}
// Read BLT file // Read BLT file
let bltFile = document.getElementById('bltFile').files[0]; let bltFile = document.getElementById('bltFile').files[0];
let text = await bltFile.text(); let text = await bltFile.text();
@ -206,7 +198,10 @@
throw evt; throw evt;
} }
worker.postMessage(text); worker.postMessage({
'numbers': document.getElementById('numbers').value,
'data': text
});
} }
</script> </script>
</body> </body>

View File

@ -1,7 +1,18 @@
importScripts('http://peterolson.github.com/BigRational.js/BigInt_BigRat.min.js', 'bundle.js'); importScripts('http://peterolson.github.com/BigRational.js/BigInt_BigRat.min.js', 'bundle.js');
onmessage = function(evt) { function sleep(ms) {
let election = py.pyRCV2.blt.readBLT(evt.data); return new Promise(resolve => setTimeout(resolve, ms));
}
onmessage = async function(evt) {
if (evt.data.numbers == 'native') {
py.pyRCV2.numbers.set_numclass(py.pyRCV2.numbers.Native);
}
if (evt.data.numbers == 'rational') {
py.pyRCV2.numbers.set_numclass(py.pyRCV2.numbers.Rational);
}
let election = py.pyRCV2.blt.readBLT(evt.data.data);
postMessage({'type': 'init', 'election': { postMessage({'type': 'init', 'election': {
'candidates': election.candidates.map(c => c.py_name) 'candidates': election.candidates.map(c => c.py_name)
}}); }});
@ -29,6 +40,7 @@ onmessage = function(evt) {
// Step election // Step election
while (true) { while (true) {
//await sleep(1000);
result = counter.step(); result = counter.step();
if (py.isinstance(result, py.pyRCV2.model.CountCompleted)) { if (py.isinstance(result, py.pyRCV2.model.CountCompleted)) {
postMessage({'type': 'done'}); postMessage({'type': 'done'});