aboutsummaryrefslogtreecommitdiffhomepage
path: root/node_modules/backo2
diff options
context:
space:
mode:
authorYaroslav De La Peña Smirnov <yaros.rus_89@live.com.mx>2017-11-29 11:44:34 +0300
committerYaroslav De La Peña Smirnov <yaros.rus_89@live.com.mx>2017-11-29 11:44:34 +0300
commit67fdec20726e48ba3a934cb25bb30d47ec4a4f29 (patch)
tree37fd9f4f0b0c20103e1646fc83021e4765de3680 /node_modules/backo2
downloadspanish-checkers-67fdec20726e48ba3a934cb25bb30d47ec4a4f29.tar.gz
spanish-checkers-67fdec20726e48ba3a934cb25bb30d47ec4a4f29.zip
Initial commit, version 0.5.3
Diffstat (limited to 'node_modules/backo2')
-rw-r--r--node_modules/backo2/.npmignore1
-rw-r--r--node_modules/backo2/History.md12
-rw-r--r--node_modules/backo2/Makefile8
-rw-r--r--node_modules/backo2/Readme.md34
-rw-r--r--node_modules/backo2/component.json11
-rw-r--r--node_modules/backo2/index.js85
-rw-r--r--node_modules/backo2/package.json78
-rw-r--r--node_modules/backo2/test/index.js18
8 files changed, 247 insertions, 0 deletions
diff --git a/node_modules/backo2/.npmignore b/node_modules/backo2/.npmignore
new file mode 100644
index 0000000..c2658d7
--- /dev/null
+++ b/node_modules/backo2/.npmignore
@@ -0,0 +1 @@
+node_modules/
diff --git a/node_modules/backo2/History.md b/node_modules/backo2/History.md
new file mode 100644
index 0000000..8eb28b8
--- /dev/null
+++ b/node_modules/backo2/History.md
@@ -0,0 +1,12 @@
+
+1.0.1 / 2014-02-17
+==================
+
+ * go away decimal point
+ * history
+
+1.0.0 / 2014-02-17
+==================
+
+ * add jitter option
+ * Initial commit
diff --git a/node_modules/backo2/Makefile b/node_modules/backo2/Makefile
new file mode 100644
index 0000000..9987df8
--- /dev/null
+++ b/node_modules/backo2/Makefile
@@ -0,0 +1,8 @@
+
+test:
+ @./node_modules/.bin/mocha \
+ --require should \
+ --reporter dot \
+ --bail
+
+.PHONY: test \ No newline at end of file
diff --git a/node_modules/backo2/Readme.md b/node_modules/backo2/Readme.md
new file mode 100644
index 0000000..0df2a39
--- /dev/null
+++ b/node_modules/backo2/Readme.md
@@ -0,0 +1,34 @@
+# backo
+
+ Simple exponential backoff because the others seem to have weird abstractions.
+
+## Installation
+
+```
+$ npm install backo
+```
+
+## Options
+
+ - `min` initial timeout in milliseconds [100]
+ - `max` max timeout [10000]
+ - `jitter` [0]
+ - `factor` [2]
+
+## Example
+
+```js
+var Backoff = require('backo');
+var backoff = new Backoff({ min: 100, max: 20000 });
+
+setTimeout(function(){
+ something.reconnect();
+}, backoff.duration());
+
+// later when something works
+backoff.reset()
+```
+
+# License
+
+ MIT
diff --git a/node_modules/backo2/component.json b/node_modules/backo2/component.json
new file mode 100644
index 0000000..994845a
--- /dev/null
+++ b/node_modules/backo2/component.json
@@ -0,0 +1,11 @@
+{
+ "name": "backo",
+ "repo": "segmentio/backo",
+ "dependencies": {},
+ "version": "1.0.1",
+ "description": "simple backoff without the weird abstractions",
+ "keywords": ["backoff"],
+ "license": "MIT",
+ "scripts": ["index.js"],
+ "main": "index.js"
+}
diff --git a/node_modules/backo2/index.js b/node_modules/backo2/index.js
new file mode 100644
index 0000000..fac4429
--- /dev/null
+++ b/node_modules/backo2/index.js
@@ -0,0 +1,85 @@
+
+/**
+ * Expose `Backoff`.
+ */
+
+module.exports = Backoff;
+
+/**
+ * Initialize backoff timer with `opts`.
+ *
+ * - `min` initial timeout in milliseconds [100]
+ * - `max` max timeout [10000]
+ * - `jitter` [0]
+ * - `factor` [2]
+ *
+ * @param {Object} opts
+ * @api public
+ */
+
+function Backoff(opts) {
+ opts = opts || {};
+ this.ms = opts.min || 100;
+ this.max = opts.max || 10000;
+ this.factor = opts.factor || 2;
+ this.jitter = opts.jitter > 0 && opts.jitter <= 1 ? opts.jitter : 0;
+ this.attempts = 0;
+}
+
+/**
+ * Return the backoff duration.
+ *
+ * @return {Number}
+ * @api public
+ */
+
+Backoff.prototype.duration = function(){
+ var ms = this.ms * Math.pow(this.factor, this.attempts++);
+ if (this.jitter) {
+ var rand = Math.random();
+ var deviation = Math.floor(rand * this.jitter * ms);
+ ms = (Math.floor(rand * 10) & 1) == 0 ? ms - deviation : ms + deviation;
+ }
+ return Math.min(ms, this.max) | 0;
+};
+
+/**
+ * Reset the number of attempts.
+ *
+ * @api public
+ */
+
+Backoff.prototype.reset = function(){
+ this.attempts = 0;
+};
+
+/**
+ * Set the minimum duration
+ *
+ * @api public
+ */
+
+Backoff.prototype.setMin = function(min){
+ this.ms = min;
+};
+
+/**
+ * Set the maximum duration
+ *
+ * @api public
+ */
+
+Backoff.prototype.setMax = function(max){
+ this.max = max;
+};
+
+/**
+ * Set the jitter
+ *
+ * @api public
+ */
+
+Backoff.prototype.setJitter = function(jitter){
+ this.jitter = jitter;
+};
+
diff --git a/node_modules/backo2/package.json b/node_modules/backo2/package.json
new file mode 100644
index 0000000..ee8315b
--- /dev/null
+++ b/node_modules/backo2/package.json
@@ -0,0 +1,78 @@
+{
+ "_args": [
+ [
+ {
+ "raw": "backo2@1.0.2",
+ "scope": null,
+ "escapedName": "backo2",
+ "name": "backo2",
+ "rawSpec": "1.0.2",
+ "spec": "1.0.2",
+ "type": "version"
+ },
+ "/mnt/e/Yaroslav/Documents/Webs/nodejs/checkers/node_modules/socket.io-client"
+ ]
+ ],
+ "_from": "backo2@1.0.2",
+ "_id": "backo2@1.0.2",
+ "_inCache": true,
+ "_location": "/backo2",
+ "_npmUser": {
+ "name": "mokesmokes",
+ "email": "mokesmokes@gmail.com"
+ },
+ "_npmVersion": "1.4.28",
+ "_phantomChildren": {},
+ "_requested": {
+ "raw": "backo2@1.0.2",
+ "scope": null,
+ "escapedName": "backo2",
+ "name": "backo2",
+ "rawSpec": "1.0.2",
+ "spec": "1.0.2",
+ "type": "version"
+ },
+ "_requiredBy": [
+ "/socket.io-client"
+ ],
+ "_resolved": "https://registry.npmjs.org/backo2/-/backo2-1.0.2.tgz",
+ "_shasum": "31ab1ac8b129363463e35b3ebb69f4dfcfba7947",
+ "_shrinkwrap": null,
+ "_spec": "backo2@1.0.2",
+ "_where": "/mnt/e/Yaroslav/Documents/Webs/nodejs/checkers/node_modules/socket.io-client",
+ "bugs": {
+ "url": "https://github.com/mokesmokes/backo/issues"
+ },
+ "dependencies": {},
+ "description": "simple backoff based on segmentio/backo",
+ "devDependencies": {
+ "mocha": "*",
+ "should": "*"
+ },
+ "directories": {},
+ "dist": {
+ "shasum": "31ab1ac8b129363463e35b3ebb69f4dfcfba7947",
+ "tarball": "https://registry.npmjs.org/backo2/-/backo2-1.0.2.tgz"
+ },
+ "gitHead": "3e695bade7756fef2295e8883bf3570a06e5d9ec",
+ "homepage": "https://github.com/mokesmokes/backo",
+ "keywords": [
+ "backoff"
+ ],
+ "license": "MIT",
+ "maintainers": [
+ {
+ "name": "mokesmokes",
+ "email": "mokesmokes@gmail.com"
+ }
+ ],
+ "name": "backo2",
+ "optionalDependencies": {},
+ "readme": "ERROR: No README data found!",
+ "repository": {
+ "type": "git",
+ "url": "git+https://github.com/mokesmokes/backo.git"
+ },
+ "scripts": {},
+ "version": "1.0.2"
+}
diff --git a/node_modules/backo2/test/index.js b/node_modules/backo2/test/index.js
new file mode 100644
index 0000000..ea1f6de
--- /dev/null
+++ b/node_modules/backo2/test/index.js
@@ -0,0 +1,18 @@
+
+var Backoff = require('..');
+var assert = require('assert');
+
+describe('.duration()', function(){
+ it('should increase the backoff', function(){
+ var b = new Backoff;
+
+ assert(100 == b.duration());
+ assert(200 == b.duration());
+ assert(400 == b.duration());
+ assert(800 == b.duration());
+
+ b.reset();
+ assert(100 == b.duration());
+ assert(200 == b.duration());
+ })
+}) \ No newline at end of file