Skip to content

Commit

Permalink
[WIP] remove initialization from nuid module creation until invoked.
Browse files Browse the repository at this point in the history
  • Loading branch information
aricart committed Dec 8, 2023
1 parent 9ab8fd6 commit 96bcaba
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion nats-base-client/nuid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ export class Nuid {
buf: Uint8Array;
seq!: number;
inc!: number;
inited: boolean;

constructor() {
this.buf = new Uint8Array(totalLen);
this.init();
this.inited = false;
}

/**
Expand All @@ -60,6 +61,7 @@ export class Nuid {
* @api private
*/
private init() {
this.inited = true;
this.setPre();
this.initSeqAndInc();
this.fillSeq();
Expand Down Expand Up @@ -108,6 +110,9 @@ export class Nuid {
* @api private
*/
next(): string {
if (!this.inited) {
this.init();
}
this.seq += this.inc;
if (this.seq > maxSeq) {
this.setPre();
Expand Down

0 comments on commit 96bcaba

Please sign in to comment.