kernel-swarm/src/id.ts

13 lines
242 B
TypeScript

function idFactory(start = 1, step = 1, limit = 2 ** 32) {
let id = start;
return function nextId() {
const nextId = id;
id += step;
if (id >= limit) id = start;
return nextId;
};
}
export const nextId = idFactory(1);