@@ -2,7 +2,7 @@ import {ChildProcess} from 'child_process'
22import initChild from './init-child.js'
33import IPOSMessaging , { iposMessagingMessage , iposMessagingType } from './messaging.js'
44import intercept from './intercept.js'
5- import { classes , deSerialize , SerializableType , SerializedType } from " ./serialize" ;
5+ import { classes , deSerialize , SerializableType , SerializedType } from ' ./serialize.js'
66
77export default class IPOS {
88 private readonly fields : Map < string , any >
@@ -154,6 +154,9 @@ export default class IPOS {
154154 if ( ! process . send )
155155 throw new Error ( `Process must have an ipc channel. Activate by passing "stdio: [<stdin>, <stdout>, <stderr>, 'ipc']" as an option.` )
156156 const messaging = new IPOSMessaging ( process )
157+ process . on ( 'close' , ( ) => {
158+ this . removeProcess ( process )
159+ } )
157160
158161 let registered = false , resolve : Function
159162 const promise : Promise < void > = new Promise ( res => resolve = res )
@@ -173,6 +176,14 @@ export default class IPOS {
173176 return promise
174177 }
175178
179+ public removeProcess ( process : ChildProcess ) : boolean {
180+ const messaging = this . processMessagingMap . get ( process )
181+ if ( ! messaging ) return false
182+ messaging . destroy ( )
183+ this . processMessagingMap . delete ( process )
184+ return true
185+ }
186+
176187 private syncProcess ( process : ChildProcess ) : Promise < void > {
177188 let resolve : Function
178189 const promise : Promise < void > = new Promise ( res => resolve = res )
0 commit comments