grpc-promise
Advanced tools
Comparing version 1.3.1 to 1.4.0
@@ -26,3 +26,3 @@ const grpc = require('grpc'); | ||
// Optional timeout definition, defaults = 50 | ||
grpc_promise.promisifyAll(client, { timeout: 100, metadata: meta, deadline: Date.now() + 1000 }); | ||
grpc_promise.promisifyAll(client, { timeout_message: 100, metadata: meta, timeout: 1000 }); // timeout in milliseconds | ||
@@ -29,0 +29,0 @@ let t = client.testStreamStream(); |
@@ -25,3 +25,3 @@ const grpc = require('grpc'); | ||
grpc_promise.promisifyAll(client, { metadata: meta, deadline: Date.now() + 1000 }); | ||
grpc_promise.promisifyAll(client, { metadata: meta, timeout: 1000 }); // timeout in milliseconds | ||
@@ -28,0 +28,0 @@ client.testStreamSimple(meta) |
@@ -25,3 +25,3 @@ const grpc = require('grpc'); | ||
grpc_promise.promisify(client, ['testSimpleSimple'], { metadata: meta, deadline: Date.now() + 1000 }); | ||
grpc_promise.promisify(client, ['testSimpleSimple'], { metadata: meta, timeout: 1000 }); // timeout in milliseconds | ||
@@ -28,0 +28,0 @@ client.testSimpleSimple() |
@@ -25,3 +25,3 @@ const grpc = require('grpc'); | ||
grpc_promise.promisifyAll(client, { metadata: meta, deadline: Date.now() + 1000 }); | ||
grpc_promise.promisifyAll(client, { metadata: meta, timeout: 1000 }); // timeout in milliseconds | ||
@@ -28,0 +28,0 @@ client.testSimpleStream() |
@@ -25,3 +25,3 @@ const grpc = require('grpc'); | ||
grpc_promise.promisifyAll(client, { metadata: meta, deadline: Date.now() + 1000 }); | ||
grpc_promise.promisifyAll(client, { metadata: meta, timeout: 1000 }); // timeout in milliseconds | ||
@@ -28,0 +28,0 @@ client.testSimpleSimple() |
@@ -12,5 +12,12 @@ | ||
this.correlationId = 0; | ||
this.timeout = options.timeout || 50; | ||
this.stream = original_function.call(client, options.metadata, { deadline: options.deadline }); | ||
this.timeout_message = options.timeout_message || 50; | ||
// Deadline is advisable to be set | ||
// It should be a timestamp value in milliseconds | ||
let deadline = undefined; | ||
if (options.timeout !== undefined) { | ||
deadline = Date.now() + options.timeout; | ||
} | ||
this.stream = original_function.call(client, options.metadata, { deadline: deadline }); | ||
this.stream.on('error', () => {}); | ||
@@ -55,3 +62,3 @@ this.stream.on('data', data => { | ||
cb('timeout'); | ||
}, this.timeout) | ||
}, this.timeout_message) | ||
}; | ||
@@ -58,0 +65,0 @@ content['id'] = id; |
@@ -7,9 +7,17 @@ | ||
this.promise = new Promise((resolve, reject) => { | ||
this.stream = original_function.call(client, options.metadata, { deadline: options.deadline }, function (error, response) { | ||
if (error) { | ||
reject(error); | ||
} else { | ||
resolve(response); | ||
// Deadline is advisable to be set | ||
// It should be a timestamp value in milliseconds | ||
let deadline = undefined; | ||
if (options.timeout !== undefined) { | ||
deadline = Date.now() + options.timeout; | ||
} | ||
this.stream = original_function.call(client, options.metadata, { deadline: deadline }, | ||
function (error, response) { | ||
if (error) { | ||
reject(error); | ||
} else { | ||
resolve(response); | ||
} | ||
} | ||
}); | ||
); | ||
}); | ||
@@ -16,0 +24,0 @@ } |
@@ -9,3 +9,3 @@ | ||
this.metadata = options.metadata; | ||
this.deadline = options.deadline || undefined; | ||
this.timeout = options.timeout || undefined; | ||
this.original_function = original_function; | ||
@@ -16,3 +16,9 @@ } | ||
return new Promise((resolve, reject) => { | ||
this.stream = this.original_function.call(this.client, content, this.metadata, { deadline: this.deadline }); | ||
// Deadline is advisable to be set | ||
// It should be a timestamp value in milliseconds | ||
let deadline = undefined; | ||
if (this.timeout !== undefined) { | ||
deadline = Date.now() + this.timeout; | ||
} | ||
this.stream = this.original_function.call(this.client, content, this.metadata, { deadline: deadline }); | ||
this.stream.on('error', error => { | ||
@@ -19,0 +25,0 @@ reject(error); |
@@ -8,3 +8,3 @@ | ||
this.metadata = options.metadata; | ||
this.deadline = options.deadline || undefined; | ||
this.timeout = options.timeout || undefined; | ||
this.original_function = original_function; | ||
@@ -15,3 +15,9 @@ } | ||
return new Promise((resolve, reject) => { | ||
this.original_function.call(this.client, content, this.metadata, { deadline: this.deadline }, | ||
// Deadline is advisable to be set | ||
// It should be a timestamp value in milliseconds | ||
let deadline = undefined; | ||
if (this.timeout !== undefined) { | ||
deadline = Date.now() + this.timeout; | ||
} | ||
this.original_function.call(this.client, content, this.metadata, { deadline: deadline }, | ||
function (error, response) { | ||
@@ -18,0 +24,0 @@ if (error) { |
{ | ||
"name": "grpc-promise", | ||
"version": "1.3.1", | ||
"version": "1.4.0", | ||
"description": "GRPC promisify module for all Request/Response types: standard and stream", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -429,3 +429,6 @@ # grpc-promise | ||
grpc_promise.promisifyAll(client, {timeout: 100}); // Optional timeout definition, defaults = 50 | ||
// Optional `timeout_message` out definition (defaults = 50) | ||
// for the response of a single message of a bidirectional stream function in grpc. | ||
// Don't confuse with `timeout` parameter used to set a deadline to the open connection. | ||
grpc_promise.promisifyAll(client, { timeout_message: 100 }); | ||
@@ -496,7 +499,10 @@ t = client.testStreamStream(); | ||
The deadline parameter is used to to set a timestamp in millisenconds for the entire call to complete: | ||
The deadline parameter is used to to set a timestamp in millisenconds for the entire call to complete. | ||
For architectural reasons and knowing that the original deadline is passed as a timestamp, | ||
grpc-module forces to set a timeout parameter in milliseconds. | ||
It means the number of milliseconds we want to wait as most for the response: | ||
```js | ||
// We give a deadline of 1 second (= 1000ms) | ||
grpc_promise.promisifyAll(client, deadline: Date.now() + 1000); | ||
grpc_promise.promisifyAll(client, { timeout: 1000 }); | ||
``` | ||
@@ -503,0 +509,0 @@ |
@@ -82,3 +82,3 @@ const BidiStreamMock = require('../../tools/grpc-mock/BidiStreamMock'); | ||
grpc_promise.promisifyAll(client, {timeout: 80}); | ||
grpc_promise.promisifyAll(client, {timeout_message: 80}); | ||
@@ -85,0 +85,0 @@ const s = client.bidiStreamReq(); |
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
49762
983
558