Comparing version 1.1.0 to 1.1.1
14
index.js
@@ -8,4 +8,6 @@ "use strict" | ||
*/ | ||
constructor({ timeout } = {}) { | ||
constructor(options = {}) { | ||
let { timeout = 0 } = options | ||
this.timeout = timeout | ||
@@ -20,3 +22,3 @@ this.tasks = new Map() | ||
*/ | ||
set(key, value, timestamp = Date.now()) { | ||
set(key, value, timestamp) { | ||
@@ -30,2 +32,6 @@ // 仅在定时队列为空时允许启动 | ||
if (!timestamp) { | ||
timestamp = Date.now() + this.timeout | ||
} | ||
return this.tasks.set(key, { value, timestamp }) | ||
@@ -68,4 +74,4 @@ | ||
for (let key of keys) { | ||
let { timestamp, value } = this.tasks.get(key) | ||
let timeout = 30 - (Date.now() - timestamp) | ||
let { value, timestamp } = this.tasks.get(key) | ||
let timeout = timestamp - Date.now() | ||
if (timeout > 0) { | ||
@@ -72,0 +78,0 @@ this.run(timeout) |
{ | ||
"name": "timechain", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "时间队列链式触发器", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -9,2 +9,14 @@ let timeChain = require('..') | ||
}, 888) | ||
}, 111) | ||
timechain.set(function (value) { | ||
console.log(value) | ||
}, 222) | ||
timechain.set(function (value) { | ||
console.log(value) | ||
}, 333) |
@@ -5,4 +5,4 @@ let timeChain = require('..') | ||
timechain.set(function(){ | ||
console.log(999) | ||
}, undefined, Date.now() + 5000) | ||
timechain.set(function(value){ | ||
console.log(value) | ||
}, 999, Date.now() + 5000) |
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
5422
7
111