protomux-rpc
Advanced tools
Comparing version 1.3.1 to 1.4.0
26
index.js
@@ -118,2 +118,4 @@ const EventEmitter = require('events') | ||
if (request.timeout) clearTimeout(request.timeout) | ||
if (error) request.reject(new Error(error)) | ||
@@ -134,2 +136,14 @@ else { | ||
_ontimeout (id) { | ||
const request = this._requests.get(id) | ||
if (request === undefined) return | ||
this._requests.delete(id) | ||
request.reject(new Error('timeout exceeded')) | ||
this._endMaybe() | ||
} | ||
get closed () { | ||
@@ -169,3 +183,4 @@ return this._channel.closed | ||
valueEncoding = this._defaultValueEncoding, | ||
requestEncoding = valueEncoding | ||
requestEncoding = valueEncoding, | ||
timeout = -1 | ||
} = options | ||
@@ -179,5 +194,8 @@ | ||
return new Promise((resolve, reject) => { | ||
this._requests.set(id, { options, resolve, reject }) | ||
}) | ||
return new Promise((resolve, reject) => this._requests.set(id, { | ||
options, | ||
resolve, | ||
reject, | ||
timeout: timeout > 0 && setTimeout(this._ontimeout.bind(this, id), timeout) | ||
})) | ||
} | ||
@@ -184,0 +202,0 @@ |
{ | ||
"name": "protomux-rpc", | ||
"version": "1.3.1", | ||
"version": "1.4.0", | ||
"description": "RPC over Protomux channels", | ||
@@ -17,3 +17,3 @@ "main": "index.js", | ||
"author": "Kasper Isager Dalsgarð <kasper@funktionel.co>", | ||
"license": "ISC", | ||
"license": "Apache-2.0", | ||
"bugs": { | ||
@@ -20,0 +20,0 @@ "url": "https://github.com/holepunchto/protomux-rpc/issues" |
@@ -96,4 +96,10 @@ # Protomux RPC | ||
Options are the same as `rpc.respond()`. | ||
Options are the same as `rpc.respond()` with the addition of: | ||
```js | ||
{ | ||
timeout: -1 // Optional request timeout in milliseconds | ||
} | ||
``` | ||
#### `rpc.event(method, value[, options])` | ||
@@ -103,3 +109,3 @@ | ||
Options are the same as `rpc.request()`. | ||
Options are the same as `rpc.respond()`. | ||
@@ -158,2 +164,2 @@ #### `rpc.cork()` | ||
ISC | ||
Apache-2.0 |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22064
215
163