From dd60a232964dbaaf1b2c76ef38e17f8481b27be7 Mon Sep 17 00:00:00 2001 From: Tobias Winkler Date: Wed, 9 May 2018 16:10:26 +0200 Subject: [PATCH] Reduce nextTick calls to prevent nextTick throttling --- scrypt-async.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/scrypt-async.js b/scrypt-async.js index d98147f..4a68891 100644 --- a/scrypt-async.js +++ b/scrypt-async.js @@ -485,14 +485,17 @@ function scrypt(password, salt, logN, r, dkLen, interruptStep, callback, encodin function interruptedFor(start, end, step, fn, donefn) { (function performStep() { - nextTick(function() { + if (start % step * 10 == 0) { + nextTick(function () { + fn(start, start + step < end ? start + step : end); + start += step; + if (start < end) performStep(); else donefn(); + }); + } else { fn(start, start + step < end ? start + step : end); start += step; - if (start < end) - performStep(); - else - donefn(); - }); + if (start < end) performStep(); else donefn(); + } })(); }