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>
|
||||
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
|
||||
let bltFile = document.getElementById('bltFile').files[0];
|
||||
let text = await bltFile.text();
|
||||
@ -206,7 +198,10 @@
|
||||
throw evt;
|
||||
}
|
||||
|
||||
worker.postMessage(text);
|
||||
worker.postMessage({
|
||||
'numbers': document.getElementById('numbers').value,
|
||||
'data': text
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
16
worker.js
16
worker.js
@ -1,7 +1,18 @@
|
||||
importScripts('http://peterolson.github.com/BigRational.js/BigInt_BigRat.min.js', 'bundle.js');
|
||||
|
||||
onmessage = function(evt) {
|
||||
let election = py.pyRCV2.blt.readBLT(evt.data);
|
||||
function sleep(ms) {
|
||||
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': {
|
||||
'candidates': election.candidates.map(c => c.py_name)
|
||||
}});
|
||||
@ -29,6 +40,7 @@ onmessage = function(evt) {
|
||||
|
||||
// Step election
|
||||
while (true) {
|
||||
//await sleep(1000);
|
||||
result = counter.step();
|
||||
if (py.isinstance(result, py.pyRCV2.model.CountCompleted)) {
|
||||
postMessage({'type': 'done'});
|
||||
|
Reference in New Issue
Block a user