diff --git a/lib/fakeworker.js b/lib/fakeworker.js index 8595eb5..4517072 100644 --- a/lib/fakeworker.js +++ b/lib/fakeworker.js @@ -15,7 +15,7 @@ function FakeWorker() { } }; - this.btoa = function(stringToEncode) + this.btoa = function(stringToEncode) { if (!this.__isWindow__) { return BASE64.encode(stringToEncode); } else { @@ -117,7 +117,33 @@ exports.create = function() { return new FakeWorker(); }; -exports.VERSIONINFO = "FakeWorker module (fakeworker.js) version 0.0.1"; +exports.repeat = function(target, worker) { + if (!(worker instanceof FakeWorker)) return; + + if (["number", "boolean"].indexOf(typeof target) > -1) { + var ms = target; + var cur = Date.now(); + var end = cur + ms; + + while (ms === true ? true : (cur < end)) { + var intervals = worker.getIntervals(); + for (var i = 0; i < intervals.length; i++) { + try { + if (typeof intervals[i].code === "function") x.code(i); + } catch (e) { + if (typeof onError === "function") onError(e, i); + } + }; + cur = Date.now(); + } + + end = Date.now(); + } + + return end; +}; + +exports.VERSIONINFO = "FakeWorker module (fakeworker.js) version 0.0.2"; exports.AUTHOR = "catswords@protonmail.com"; exports.global = global; exports.require = global.require;