Skip to content

Commit 79ce2b5

Browse files
committed
refactor: bind heart methods .beat and .alive
This allows the functions to maintain access to the Heart instance (or `this`) even when they are passed to other functions. We do this because we pass both `isActive` and `beat` to `heartbeatTimer`.
1 parent e00d4b5 commit 79ce2b5

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/node/heart.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ export class Heart {
99
private heartbeatInterval = 60000
1010
public lastHeartbeat = 0
1111

12-
public constructor(private readonly heartbeatPath: string, private readonly isActive: () => Promise<boolean>) {}
12+
public constructor(private readonly heartbeatPath: string, private readonly isActive: () => Promise<boolean>) {
13+
this.beat = this.beat.bind(this)
14+
this.alive = this.alive.bind(this)
15+
}
1316

1417
public alive(): boolean {
1518
const now = Date.now()

0 commit comments

Comments
 (0)