diff --git a/test.html b/test.html index 3bb3d31..9411d9a 100644 --- a/test.html +++ b/test.html @@ -42,14 +42,6 @@ diff --git a/worker.js b/worker.js index 59fd41b..70b3495 100644 --- a/worker.js +++ b/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'});