1
This commit is contained in:
32
nodejs/node_modules/long-timeout/README.md
generated
vendored
Executable file
32
nodejs/node_modules/long-timeout/README.md
generated
vendored
Executable file
@ -0,0 +1,32 @@
|
||||
# Long timeouts
|
||||
|
||||
Long timeout makes it possible to have a timeout or interval that is longer than 24.8 days (2^31-1 milliseconds).
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
var lt = require('long-timeout')
|
||||
|
||||
var timeout = lt.setTimeout(function() {
|
||||
console.log('in 30 days')
|
||||
}, 1000 * 60 * 60 * 24 * 30)
|
||||
|
||||
var interval = lt.setInterval(function() {
|
||||
console.log('every 30 days')
|
||||
}, 1000 * 60 * 60 * 24 * 30)
|
||||
|
||||
|
||||
// Clear them
|
||||
lt.clearTimeout(timeout)
|
||||
lt.clearInterval(interval)
|
||||
```
|
||||
|
||||
## Install
|
||||
|
||||
npm install long-timeout
|
||||
|
||||
|
||||
## Licence
|
||||
|
||||
MIT
|
||||
23
nodejs/node_modules/long-timeout/example.js
generated
vendored
Executable file
23
nodejs/node_modules/long-timeout/example.js
generated
vendored
Executable file
@ -0,0 +1,23 @@
|
||||
var lt = require('./')
|
||||
|
||||
/*
|
||||
Timeouts
|
||||
*/
|
||||
lt.setTimeout(function() {
|
||||
console.log('in a long time')
|
||||
}, Number.MAX_VALUE)
|
||||
|
||||
lt.setTimeout(function() {
|
||||
console.log('2 seconds')
|
||||
}, 2000)
|
||||
|
||||
/*
|
||||
Intervals
|
||||
*/
|
||||
lt.setInterval(function() {
|
||||
console.log('long interval')
|
||||
}, Number.MAX_VALUE)
|
||||
|
||||
lt.setInterval(function() {
|
||||
console.log("2 second interval")
|
||||
}, 2000)
|
||||
101
nodejs/node_modules/long-timeout/index.js
generated
vendored
Executable file
101
nodejs/node_modules/long-timeout/index.js
generated
vendored
Executable file
@ -0,0 +1,101 @@
|
||||
|
||||
var TIMEOUT_MAX = 2147483647; // 2^31-1
|
||||
|
||||
exports.setTimeout = function(listener, after) {
|
||||
return new Timeout(listener, after)
|
||||
}
|
||||
exports.setInterval = function(listener, after) {
|
||||
return new Interval(listener, after)
|
||||
}
|
||||
exports.clearTimeout = function(timer) {
|
||||
if (timer) timer.close()
|
||||
}
|
||||
exports.clearInterval = exports.clearTimeout
|
||||
|
||||
exports.Timeout = Timeout
|
||||
exports.Interval = Interval
|
||||
|
||||
function Timeout(listener, after) {
|
||||
this.listener = listener
|
||||
this.after = after
|
||||
this.unreffed = false
|
||||
this.start()
|
||||
}
|
||||
|
||||
Timeout.prototype.unref = function() {
|
||||
if (!this.unreffed) {
|
||||
this.unreffed = true
|
||||
this.timeout.unref()
|
||||
}
|
||||
}
|
||||
|
||||
Timeout.prototype.ref = function() {
|
||||
if (this.unreffed) {
|
||||
this.unreffed = false
|
||||
this.timeout.ref()
|
||||
}
|
||||
}
|
||||
|
||||
Timeout.prototype.start = function() {
|
||||
if (this.after <= TIMEOUT_MAX) {
|
||||
this.timeout = setTimeout(this.listener, this.after)
|
||||
} else {
|
||||
var self = this
|
||||
this.timeout = setTimeout(function() {
|
||||
self.after -= TIMEOUT_MAX
|
||||
self.start()
|
||||
}, TIMEOUT_MAX)
|
||||
}
|
||||
if (this.unreffed) {
|
||||
this.timeout.unref()
|
||||
}
|
||||
}
|
||||
|
||||
Timeout.prototype.close = function() {
|
||||
clearTimeout(this.timeout)
|
||||
}
|
||||
|
||||
function Interval(listener, after) {
|
||||
this.listener = listener
|
||||
this.after = this.timeLeft = after
|
||||
this.unreffed = false
|
||||
this.start()
|
||||
}
|
||||
|
||||
Interval.prototype.unref = function() {
|
||||
if (!this.unreffed) {
|
||||
this.unreffed = true
|
||||
this.timeout.unref()
|
||||
}
|
||||
}
|
||||
|
||||
Interval.prototype.ref = function() {
|
||||
if (this.unreffed) {
|
||||
this.unreffed = false
|
||||
this.timeout.ref()
|
||||
}
|
||||
}
|
||||
|
||||
Interval.prototype.start = function() {
|
||||
var self = this
|
||||
|
||||
if (this.timeLeft <= TIMEOUT_MAX) {
|
||||
this.timeout = setTimeout(function() {
|
||||
self.listener()
|
||||
self.timeLeft = self.after
|
||||
self.start()
|
||||
}, this.timeLeft)
|
||||
} else {
|
||||
this.timeout = setTimeout(function() {
|
||||
self.timeLeft -= TIMEOUT_MAX
|
||||
self.start()
|
||||
}, TIMEOUT_MAX)
|
||||
}
|
||||
if (this.unreffed) {
|
||||
this.timeout.unref()
|
||||
}
|
||||
}
|
||||
|
||||
Interval.prototype.close = function() {
|
||||
Timeout.prototype.close.apply(this, arguments)
|
||||
}
|
||||
54
nodejs/node_modules/long-timeout/package.json
generated
vendored
Executable file
54
nodejs/node_modules/long-timeout/package.json
generated
vendored
Executable file
@ -0,0 +1,54 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"long-timeout@0.1.1",
|
||||
"/www/wwwroot/Adminx.cc/nodejs"
|
||||
]
|
||||
],
|
||||
"_from": "long-timeout@0.1.1",
|
||||
"_id": "long-timeout@0.1.1",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-lyHXiLR+C8taJMLivuGg2lXatRQ=",
|
||||
"_location": "/long-timeout",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "long-timeout@0.1.1",
|
||||
"name": "long-timeout",
|
||||
"escapedName": "long-timeout",
|
||||
"rawSpec": "0.1.1",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "0.1.1"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/node-schedule"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/long-timeout/-/long-timeout-0.1.1.tgz",
|
||||
"_spec": "0.1.1",
|
||||
"_where": "/www/wwwroot/Adminx.cc/nodejs",
|
||||
"author": {
|
||||
"name": "Christian Tellnes",
|
||||
"email": "christian@tellnes.no",
|
||||
"url": "http://christian.tellnes.com/"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/tellnes/long-timeout/issues"
|
||||
},
|
||||
"description": "Long timeout makes it possible to have a timeout or interval that is longer than 24.8 days (2^31-1 milliseconds).",
|
||||
"homepage": "https://github.com/tellnes/long-timeout",
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"name": "long-timeout",
|
||||
"publishConfig": {
|
||||
"registry": "https://registry.npmjs.org/"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/tellnes/long-timeout.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"version": "0.1.1"
|
||||
}
|
||||
Reference in New Issue
Block a user