(msg, cmd, swallowErrors, callback)
| 14 | } |
| 15 | |
| 16 | _request(msg, cmd, swallowErrors, callback) { |
| 17 | const self = this; |
| 18 | |
| 19 | if (!this.child.connected) return onclose(); |
| 20 | this.child._send(msg, undefined, swallowErrors); |
| 21 | |
| 22 | function onclose() { |
| 23 | self.child.removeListener('internalMessage', onreply); |
| 24 | callback(new ERR_CHILD_CLOSED_BEFORE_REPLY()); |
| 25 | } |
| 26 | |
| 27 | function onreply(msg) { |
| 28 | if (!(msg.cmd === cmd && msg.key === self.key)) return; |
| 29 | self.child.removeListener('disconnect', onclose); |
| 30 | self.child.removeListener('internalMessage', onreply); |
| 31 | |
| 32 | callback(null, msg); |
| 33 | } |
| 34 | |
| 35 | this.child.once('disconnect', onclose); |
| 36 | this.child.on('internalMessage', onreply); |
| 37 | } |
| 38 | |
| 39 | close(callback) { |
| 40 | this._request({ |
no test coverage detected