@weedzcokie/scheduler
Advanced tools
Comparing version 1.0.1 to 1.0.2
25
main.js
@@ -6,3 +6,3 @@ /** | ||
* @prop {() => unknown | Promise<unknown>} fn | ||
* @prop {NodeJS.Timeout} timeout | ||
* @prop {number} timeout | ||
*/ | ||
@@ -33,3 +33,6 @@ | ||
const timeDrift = Date.now() - start; | ||
task.timeout = setTimeout(() => runTask(task), task.period - timeDrift); | ||
// Make sure we don't restart a stopped task | ||
if (task.timeout) { | ||
task.timeout = setTimeout(() => runTask(task), task.period - timeDrift); | ||
} | ||
} | ||
@@ -64,2 +67,3 @@ | ||
clearTimeout(task.timeout); | ||
task.timeout = 0; | ||
return true; | ||
@@ -69,1 +73,18 @@ } | ||
} | ||
/** | ||
* @param {string} name | ||
* @param {null|number} [offset=null] | ||
* @param {number} [period=0] | ||
*/ | ||
export function rescheduleTask(name, period = null, offset = 0) { | ||
const task = tasks.get(name); | ||
if (task) { | ||
if (period !== null) { | ||
task.period = period; | ||
} | ||
clearTimeout(task.timeout); | ||
task.timeout = setTimeout(() => runTask(task), task.period + offset); | ||
return true; | ||
} | ||
return false; | ||
} |
{ | ||
"name": "@weedzcokie/scheduler", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "type": "module", |
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
3615
78