Comparing version 0.2.1 to 0.2.2
@@ -6,3 +6,15 @@ // Generated by CoffeeScript 1.4.0 | ||
module.exports = (function() { | ||
var ALIASES, IntervalTask, Task, TimeoutTask, Timer, alias, aliases, bindAll, key, taskFactoryFor, timer, validate; | ||
var ALIASES, CLEAN_THRESHOLD, INITIAL_THRESHOLD, IntervalTask, LinkedList, Task, TimeoutTask, Timer, alias, aliases, bindAll, key, taskFactoryFor, timer, validate; | ||
INITIAL_THRESHOLD = 10; | ||
CLEAN_THRESHOLD = 1.10; | ||
LinkedList = require('linkedlist'); | ||
LinkedList.prototype.remove = function(ll, item) { | ||
ll.resetCursor(); | ||
while (ll.next() && item !== ll.current) {} | ||
if (ll.current !== item) { | ||
return false; | ||
} | ||
ll.removeCurrent(); | ||
return true; | ||
}; | ||
alias = function(Klass, action, names) { | ||
@@ -174,2 +186,3 @@ var name, _i, _len, _results; | ||
} | ||
this._checkAndClean(); | ||
return task; | ||
@@ -184,4 +197,7 @@ }; | ||
Timer.prototype._lastCleanedLength = 0; | ||
function Timer() { | ||
this.tasks = []; | ||
this.tasks = new LinkedList; | ||
this._lastCleanedLength = INITIAL_THRESHOLD; | ||
bindAll(this, Timer); | ||
@@ -199,7 +215,5 @@ } | ||
Timer.prototype.pause = function() { | ||
var task, _i, _len, _ref; | ||
_ref = this.tasks; | ||
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
task = _ref[_i]; | ||
task.pause(); | ||
this.tasks.resetCursor(); | ||
while (this.tasks.next()) { | ||
this.tasks.current.pause(); | ||
} | ||
@@ -210,7 +224,5 @@ return this.paused = true; | ||
Timer.prototype.resume = function() { | ||
var task, _i, _len, _ref; | ||
_ref = this.tasks; | ||
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
task = _ref[_i]; | ||
task.resume(); | ||
this.tasks.resetCursor(); | ||
while (this.tasks.next()) { | ||
this.tasks.current.resume(); | ||
} | ||
@@ -221,8 +233,7 @@ return this.paused = false; | ||
Timer.prototype.wind = function(time) { | ||
var task, _i, _len, _ref, _results; | ||
_ref = this.tasks; | ||
var _results; | ||
this.tasks.resetCursor(); | ||
_results = []; | ||
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
task = _ref[_i]; | ||
_results.push(task.wind(time)); | ||
while (this.tasks.next()) { | ||
_results.push(this.tasks.current.wind(time)); | ||
} | ||
@@ -232,2 +243,15 @@ return _results; | ||
Timer.prototype._checkAndClean = function() { | ||
if (!(this.tasks.length > this._lastCleanedLength * CLEAN_THRESHOLD)) { | ||
return; | ||
} | ||
this.tasks.resetCursor(); | ||
while (this.tasks.next()) { | ||
if (this.tasks.current.canceled) { | ||
this.tasks.removeCurrent(); | ||
} | ||
} | ||
return this._lastCleanedLength = this.tasks.length; | ||
}; | ||
return Timer; | ||
@@ -234,0 +258,0 @@ |
{ | ||
"name": "timer-shim", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"description": "Test-friendly timer function replacements.", | ||
@@ -30,3 +30,6 @@ "main": "index.js", | ||
"mocha-subject": "~0.1.1" | ||
}, | ||
"dependencies": { | ||
"linkedlist": "~1.0.1" | ||
} | ||
} |
@@ -33,2 +33,8 @@ | ||
Internally a [node-linkedlist](https://github.com/kilianc/node-linkedlist) is used to | ||
track scheduled tasks with very basic adaptive cleanup. From a set of benchmarks I have | ||
ran, using TIMER-SHIM vs setTimeout adds no more than 100ms overhead for 100,000 tasks on | ||
a decent MBA. This overhead will be completly togglable in the future so you can have | ||
shims for tests and zero overhead for production. | ||
# INSTALL | ||
@@ -132,2 +138,4 @@ | ||
instead. | ||
* Ability to un-shim the the shims and send calls directly to setTimeout/setInterval | ||
virtually removing any perf and mem impact (i.e. in production.) | ||
* Performance optimizations. | ||
@@ -134,0 +142,0 @@ * nextTick support? |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
28514
12
262
150
0
1
+ Addedlinkedlist@~1.0.1
+ Addedlinkedlist@1.0.1(transitive)