File tree Expand file tree Collapse file tree 1 file changed +18
-11
lines changed Expand file tree Collapse file tree 1 file changed +18
-11
lines changed Original file line number Diff line number Diff line change @@ -33,17 +33,7 @@ export class Heart {
33
33
if ( typeof this . heartbeatTimer !== "undefined" ) {
34
34
clearTimeout ( this . heartbeatTimer )
35
35
}
36
- this . heartbeatTimer = setTimeout ( ( ) => {
37
- this . isActive ( )
38
- . then ( ( active ) => {
39
- if ( active ) {
40
- this . beat ( )
41
- }
42
- } )
43
- . catch ( ( error ) => {
44
- logger . warn ( error . message )
45
- } )
46
- } , this . heartbeatInterval )
36
+ this . heartbeatTimer = setTimeout ( async ( ) => await heartbeatTimer ( this . isActive , this . beat ) , this . heartbeatInterval )
47
37
}
48
38
49
39
/**
@@ -55,3 +45,20 @@ export class Heart {
55
45
}
56
46
}
57
47
}
48
+
49
+ /**
50
+ * Helper function for the heartbeatTimer.
51
+ *
52
+ * If heartbeat is active, call beat. Otherwise do nothing.
53
+ *
54
+ * Extracted to make it easier to test.
55
+ */
56
+ export async function heartbeatTimer ( isActive : Heart [ "isActive" ] , beat : Heart [ "beat" ] ) {
57
+ try {
58
+ if ( await isActive ( ) ) {
59
+ beat ( )
60
+ }
61
+ } catch ( error : unknown ) {
62
+ logger . warn ( ( error as Error ) . message )
63
+ }
64
+ }
You can’t perform that action at this time.
0 commit comments