Permalink
Browse files

Run both proof of work modules simultaneously

  • Loading branch information...
numtel committed Feb 23, 2018
1 parent 85ef04e commit 302801443dea4e505688db41bb55c29035aed274
Showing with 19 additions and 8 deletions.
  1. +1 −1 gulpfile.js
  2. +18 −7 resources/assets/js/custom.js
@@ -36,4 +36,4 @@ elixir(function(mix) {
.copy('resources/assets/js/pow.js', 'public/js/pow.js')
.copy('resources/assets/js/pow.wasm', 'public/pow.wasm')
.copy('resources/assets/js/pow.wasm', 'public/js/pow.wasm');
});
});
@@ -552,20 +552,31 @@ $(document).ready(function(){
return setTimeout(clientPoW, 1000);
var finished = function(work) {
// Do not execute this callback again if WebGL returned before
// it was able to be stopped
if(finished === null) return;
finished = null; // In case of WebAssembly finishing first
pow_terminate(workers); // In case of WebGL finishing first
logger.log('PoW found for ' + hash + ": " + work);
wallet.updateWorkPool(hash, work);
setTimeout(clientPoW, 1000);
};
pow_workers = pow_initiate(NaN, 'js/');
pow_callback(pow_workers, hash, function() {
logger.log('Working locally on ' + hash);
}, finished);
try {
NanoWebglPow(hash, finished);
NanoWebglPow(hash, finished, function(n) {
// If WebAssembly finished first, do not continue with WebGL
if(finished === null) return true;
});
} catch(error) {
if(error.message === 'webgl2_required') {
// Fallback to WebAssembly Proof of Work
pow_workers = pow_initiate(NaN, 'js/');
pow_callback(pow_workers, hash, function() {
logger.log('Working locally on ' + hash);
}, finished);
// Do nothing, WebAssembly is calculating as well
} else throw error;
}
}
@@ -1800,4 +1811,4 @@ $(document).ready(function(){
// raiwallet pay listeners
$('#pay-login-button').click(signInAndPay);
$('#confirm-pay').click(confirmPayment);
});
});

0 comments on commit 3028014

Please sign in to comment.