'use strict';
const { ChoreError } = require('./errors');
-const { fileScope } = require('./common');
+const { fileScope } = require('@squeep/log-helper');
const _fileScope = fileScope(__filename);
/**
- *
+ * @typedef {object} ConsoleLike
+ * @property {Function} debug debug
+ * @property {Function} error error
+ */
+/**
+ * @typedef {object} Chore
+ * @property {boolean} isRunning actively being executed
+ * @property {Function} choreFn task handler to invoke
+ * @property {number} intervalMs period to wait between invocations
+ * @property {NodeJS.Timeout=} timeoutObj active timeout
+ * @property {Date=} nextSchedule time of next invocation
+ */
+
+/**
+ * Thin wrapper for wrangling periodic tasks with setTimeout.
*/
class Chores {
/**
- * @param {ConsoleLike} logger
+ * @param {ConsoleLike} logger logger object
*/
constructor(logger) {
this.logger = logger;
this.chores = {};
}
+ /**
+ *
+ * @param {string} choreName chore name
+ * @returns {Chore} chore
+ */
_getChore(choreName) {
const chore = this.chores[choreName]; // eslint-disable-line security/detect-object-injection
if (!chore) {
/**
* Register a chore task to be called every intervalMs.
* Zero interval will only register task, will not schedule any calls.
- * @param {String} choreName
- * @param {() => Promise(void)} choreFn
- * @param {Number} intervalMs
+ * @param {string} choreName chore name
+ * @param {() => Promise<void>} choreFn chore function
+ * @param {number} intervalMs invocation period
*/
establishChore(choreName, choreFn, intervalMs = 0) {
const _scope = _fileScope('establishChore');
/**
* Invoke a chore task off-schedule, with any arguments.
* Resets timer of any next scheduled call.
- * @param {String} choreName
- * @param {...any} choreArgs
- * @returns {Promise<void>}
+ * @param {string} choreName chore name
+ * @param {...any} choreArgs additional args to pass to chore function
+ * @returns {Promise<void>} nothing
*/
async runChore(choreName, ...choreArgs) {
const _scope = _fileScope('runChore');
/**
* Stop a chore from being scheduled to run.
- * @param {String} choreName
+ * @param {string} choreName chore name
*/
stopChore(choreName) {
const _scope = _fileScope('stopChore');
} // Chores
-module.exports = Chores;
\ No newline at end of file
+module.exports = Chores;