@@ -8,7 +8,7 @@ export interface Config {
8
8
9
9
export const name = 'daemon'
10
10
11
- export function apply ( ctx : Context , config : Config = { } ) {
11
+ export function * apply ( ctx : Context , config : Config = { } ) {
12
12
function handleSignal ( signal : NodeJS . Signals ) {
13
13
// prevent restarting when child process is exiting
14
14
if ( config . autoRestart ) {
@@ -18,15 +18,16 @@ export function apply(ctx: Context, config: Config = {}) {
18
18
ctx . parallel ( 'exit' , signal ) . finally ( ( ) => process . exit ( ) )
19
19
}
20
20
21
- ctx . effect ( function * ( ) {
22
- process . on ( 'SIGINT' , handleSignal )
23
- yield ( ) => process . off ( 'SIGINT' , handleSignal )
24
- process . on ( 'SIGTERM' , handleSignal )
25
- yield ( ) => process . off ( 'SIGTERM' , handleSignal )
26
- } , 'process.on(signal)' )
21
+ process . on ( 'SIGINT' , handleSignal )
22
+ yield ( ) => process . off ( 'SIGINT' , handleSignal )
23
+ process . on ( 'SIGTERM' , handleSignal )
24
+ yield ( ) => process . off ( 'SIGTERM' , handleSignal )
27
25
28
26
process . send ! ( { type : 'start' , body : config } )
29
- config . heartbeatInterval && setInterval ( ( ) => {
30
- process . send ! ( { type : 'heartbeat' } )
31
- } , config . heartbeatInterval )
27
+ if ( config . heartbeatInterval ) {
28
+ const timer = setInterval ( ( ) => {
29
+ process . send ! ( { type : 'heartbeat' } )
30
+ } , config . heartbeatInterval )
31
+ yield ( ) => clearInterval ( timer )
32
+ }
32
33
}
0 commit comments