dash-core
Version:
A foundational toolkit of types, collections, services, and architectural patterns designed to accelerate application development.
34 lines (33 loc) • 1.22 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Wait = Wait;
exports.CreateInterval = CreateInterval;
exports.CreateTimeout = CreateTimeout;
class Tasks {
/** Waits for the given `TimeSpan` before resolving. */
static wait(timeSpan) {
return new Promise((resolve) => setTimeout(resolve, timeSpan.totalMilliseconds));
}
}
/** Waits for the given `TimeSpan` before resolving. */
function Wait(timeSpan) {
return Tasks.wait(timeSpan);
}
/**
* Creates a recurring interval that calls the callback at the specified interval.
* @param {() => void} callback - Function to call on each interval.
* @param {TimeSpan} timeSpan - Duration between calls.
* @returns {NodeJS.Timeout} Interval identifier.
*/
function CreateInterval(callback, timeSpan) {
return setInterval(callback, timeSpan.totalMilliseconds);
}
/**
* Creates a timeout to call the callback after the specified delay.
* @param {() => void} callback - Function to call after the delay.
* @param {TimeSpan} timeSpan - Delay duration.
* @returns {NodeJS.Timeout} Timeout identifier.
*/
function CreateTimeout(callback, timeSpan) {
return setTimeout(callback, timeSpan.totalMilliseconds);
}