dash-core
Version:
A foundational toolkit of types, collections, services, and architectural patterns designed to accelerate application development.
42 lines (41 loc) • 1.23 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Rate = void 0;
const dash_core_1 = require("dash-core");
/**
* Represents a frequency as occurrences per given time span.
* Provides a computed delay between each occurrence.
*/
class Rate {
/** Occurrences per interval */
rate;
/** Time span over which the rate applies */
interval;
/**
* @param rate Number of occurrences per interval (must be > 0)
* @param interval Time span over which the rate applies
*/
constructor(rate, interval) {
if (rate <= 0) {
throw new Error("Rate must be a positive number");
}
this.rate = rate;
this.interval = interval;
}
/**
* Create a Rate instance.
* @param rate Number of occurrences per interval (must be > 0)
* @param interval Time span over which the rate applies
*/
static of(rate, interval) {
return new Rate(rate, interval);
}
/**
* Delay between occurrences as a TimeSpan.
*/
get delay() {
const millis = this.interval.totalMilliseconds / this.rate;
return dash_core_1.TimeSpan.fromMilliseconds(millis);
}
}
exports.Rate = Rate;