Fix logic error resulting in numbers setting not being observed
This commit is contained in:
parent
93f0100856
commit
07afc233b4
13
test.html
13
test.html
@ -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>
|
||||||
|
16
worker.js
16
worker.js
@ -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'});
|
||||||
|
Reference in New Issue
Block a user