Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

timer-shim

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

timer-shim - npm Package Compare versions

Comparing version 0.2.1 to 0.2.2

.travis.yml

58

lib/timer-shim.js

@@ -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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc