-
-
Save kumavis/76b847236eb3ff27ffbfa36a841217e1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const eos = require('end-of-stream') | |
eos(portStream, (err) => { | |
console.log('out stream ended', err) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Duplex = require('readable-stream').Duplex | |
const inherits = require('util').inherits | |
module.exports = PortDuplexStream | |
inherits(PortDuplexStream, Duplex) | |
function PortDuplexStream (port) { | |
Duplex.call(this, { | |
objectMode: true, | |
}) | |
this._port = port | |
port.onMessage.addListener(this._onMessage.bind(this)) | |
port.onDisconnect.addListener(this._onDisconnect.bind(this)) | |
} | |
PortDuplexStream.prototype._onDisconnect = function () { | |
this.emit('end') | |
this.emit('finish') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment