@toreda/time
Version:
Simple, small footprint library for common time operations and converting between units of time.
20 lines (19 loc) • 713 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.timerCallbackGroupIdNext = timerCallbackGroupIdNext;
const COUNTER_KEY = Symbol.for('@toreda/time/timerCallbackGroupIdCounter');
/**
* Returns the next auto-incrementing TimerCallbackGroup id. The counter is
* stored on `globalThis` under a registered Symbol so every module that
* imports this helper — even across duplicated copies of the package — shares
* the same sequence.
*
* @category Timers
*/
function timerCallbackGroupIdNext() {
var _a;
const g = globalThis;
const next = ((_a = g[COUNTER_KEY]) !== null && _a !== void 0 ? _a : 0) + 1;
g[COUNTER_KEY] = next;
return `timer_${next}`;
}