diff options
author | Dan Finlay <542863+danfinlay@users.noreply.github.com> | 2018-04-21 05:10:05 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-21 05:10:05 +0800 |
commit | 74c419f9b65841c2966d1fe3b7414bf11e09e0d8 (patch) | |
tree | b685af5f2383a6d1159ed339e29b831f094aa079 /app/scripts/lib/port-stream.js | |
parent | 00efcf9e8ba34d448b628c98d32ad12d5be2ffc9 (diff) | |
parent | 8636f3bae547ace7d099a3ed516bf013dfe3858e (diff) | |
download | tangerine-wallet-browser-74c419f9b65841c2966d1fe3b7414bf11e09e0d8.tar tangerine-wallet-browser-74c419f9b65841c2966d1fe3b7414bf11e09e0d8.tar.gz tangerine-wallet-browser-74c419f9b65841c2966d1fe3b7414bf11e09e0d8.tar.bz2 tangerine-wallet-browser-74c419f9b65841c2966d1fe3b7414bf11e09e0d8.tar.lz tangerine-wallet-browser-74c419f9b65841c2966d1fe3b7414bf11e09e0d8.tar.xz tangerine-wallet-browser-74c419f9b65841c2966d1fe3b7414bf11e09e0d8.tar.zst tangerine-wallet-browser-74c419f9b65841c2966d1fe3b7414bf11e09e0d8.zip |
Merge pull request #4020 from MetaMask/i3941-jsdoc-bitpshr
Documentation
Diffstat (limited to 'app/scripts/lib/port-stream.js')
-rw-r--r-- | app/scripts/lib/port-stream.js | 37 |
1 files changed, 33 insertions, 4 deletions
diff --git a/app/scripts/lib/port-stream.js b/app/scripts/lib/port-stream.js index a9716fb00..5c4224fd9 100644 --- a/app/scripts/lib/port-stream.js +++ b/app/scripts/lib/port-stream.js @@ -6,6 +6,13 @@ module.exports = PortDuplexStream inherits(PortDuplexStream, Duplex) +/** + * Creates a stream that's both readable and writable. + * The stream supports arbitrary objects. + * + * @class + * @param {Object} port Remote Port object + */ function PortDuplexStream (port) { Duplex.call(this, { objectMode: true, @@ -15,8 +22,13 @@ function PortDuplexStream (port) { port.onDisconnect.addListener(this._onDisconnect.bind(this)) } -// private - +/** + * Callback triggered when a message is received from + * the remote Port associated with this Stream. + * + * @private + * @param {Object} msg - Payload from the onMessage listener of Port + */ PortDuplexStream.prototype._onMessage = function (msg) { if (Buffer.isBuffer(msg)) { delete msg._isBuffer @@ -27,14 +39,31 @@ PortDuplexStream.prototype._onMessage = function (msg) { } } +/** + * Callback triggered when the remote Port + * associated with this Stream disconnects. + * + * @private + */ PortDuplexStream.prototype._onDisconnect = function () { this.destroy() } -// stream plumbing - +/** + * Explicitly sets read operations to a no-op + */ PortDuplexStream.prototype._read = noop + +/** + * Called internally when data should be written to + * this writable stream. + * + * @private + * @param {*} msg Arbitrary object to write + * @param {string} encoding Encoding to use when writing payload + * @param {Function} cb Called when writing is complete or an error occurs + */ PortDuplexStream.prototype._write = function (msg, encoding, cb) { try { if (Buffer.isBuffer(msg)) { |