Skip to content

Commit

Permalink
✨ emit changedResendStatus for easy recovery
Browse files Browse the repository at this point in the history
  • Loading branch information
lukas-runge committed Jul 22, 2024
1 parent c00a6b0 commit d32bac4
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/sender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ export class Sender extends EventEmitter {

private sequence = 0;

private resendStatus = false;

#loopId: NodeJS.Timeout | undefined;

/**
Expand Down Expand Up @@ -126,9 +128,21 @@ export class Sender extends EventEmitter {

private reSend() {
if (this.#latestPacketOptions) {
this.send(this.#latestPacketOptions).catch((err) =>
this.emit('error', err),
);
this.send(this.#latestPacketOptions)
.then(() => {
this.updateResendStatus(true);
})
.catch((err) => {
this.updateResendStatus(false);
this.emit('error', err);
});
}
}

private updateResendStatus(success: boolean) {
if (success !== this.resendStatus) {
this.resendStatus = success;
this.emit('changedResendStatus', success);
}
}

Expand Down

0 comments on commit d32bac4

Please sign in to comment.