+18
-1
@@ -5,2 +5,3 @@ const safetyCatch = require('safety-catch') | ||
| const m = require('./lib/messages') | ||
| const errors = require('./lib/errors') | ||
| const { type: t, stream: s } = require('./lib/constants') | ||
@@ -40,6 +41,11 @@ const IncomingEvent = require('./lib/incoming-event') | ||
| this._onerror = this._onerror.bind(this) | ||
| this._onclose = this._onclose.bind(this) | ||
| this._ondata = this._ondata.bind(this) | ||
| this._ondrain = this._ondrain.bind(this) | ||
| this._stream.on('error', this._onerror).on('data', this._ondata).on('drain', this._ondrain) | ||
| this._stream | ||
| .on('error', this._onerror) | ||
| .on('close', this._onclose) | ||
| .on('data', this._ondata) | ||
| .on('drain', this._ondrain) | ||
| } | ||
@@ -180,2 +186,13 @@ | ||
| _onerror(err) { | ||
| this._teardown(err) | ||
| } | ||
| _onclose() { | ||
| // A clean close of the underlying stream leaves in-flight requests and | ||
| // responses with nowhere to complete, so tear them down as if the channel | ||
| // had errored. | ||
| this._teardown(errors.CHANNEL_CLOSED('Channel closed')) | ||
| } | ||
| _teardown(err) { | ||
| this._ondrain(err) | ||
@@ -182,0 +199,0 @@ |
+2
-0
| declare class RPCError extends Error { | ||
| static UNKNOWN_MESSAGE(msg: string): RPCError | ||
| static ALREADY_SENT(msg: string): RPCError | ||
| static ALREADY_RECEIVED(msg: string): RPCError | ||
| static CHANNEL_CLOSED(msg: string): RPCError | ||
| } | ||
| export = RPCError |
+4
-0
@@ -26,2 +26,6 @@ module.exports = class RPCError extends Error { | ||
| } | ||
| static CHANNEL_CLOSED(msg) { | ||
| return new RPCError(msg, 'CHANNEL_CLOSED', RPCError.CHANNEL_CLOSED) | ||
| } | ||
| } |
+1
-1
| { | ||
| "name": "bare-rpc", | ||
| "version": "1.3.6", | ||
| "version": "1.3.7", | ||
| "description": "librpc ABI compatible RPC for Bare", | ||
@@ -5,0 +5,0 @@ "exports": { |
47565
1.38%1008
2.02%