Skip to content

Commit

Permalink
pubsub: add ability to pass timeout to publish (#2232)
Browse files Browse the repository at this point in the history
  • Loading branch information
dennismartensson authored and stephenplusplus committed Apr 20, 2017
1 parent 9433444 commit 19ab795
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ Anand Suresh
Brett Bergmann
Jesse Friedman
Zach Bjornson <[email protected]>

Greta.io
Dennis Mårtensson <[email protected]>
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Ben Stahl <[email protected]>
Brett Bergmann <[email protected]>
Burcu Dogan <[email protected]>
Cristian Almstrand <[email protected]>
Dennis Mårtensson <[email protected]>
Gor Martsen <[email protected]>
Hector Rovira <[email protected]>
Ido Shamun <[email protected]>
Expand Down
7 changes: 7 additions & 0 deletions packages/pubsub/src/topic.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,8 @@ Topic.prototype.getSubscriptionsStream = function(options) {
* @param {object=} options - Configuration object.
* @param {boolean} options.raw - Enable if you require setting attributes on
* your messages.
* @param {number} options.timeout - Set a maximum amount of time in
* milliseconds before giving up if no response is received.
* @param {function=} callback - The callback function.
*
* @example
Expand Down Expand Up @@ -435,6 +437,7 @@ Topic.prototype.getSubscriptionsStream = function(options) {
* var messageIds = data[0];
* var apiResponse = data[1];
* });
*
*/
Topic.prototype.publish = function(messages, options, callback) {
messages = arrify(messages);
Expand All @@ -456,6 +459,10 @@ Topic.prototype.publish = function(messages, options, callback) {
method: 'publish',
};

if (is.number(options.timeout)) {
protoOpts.timeout = options.timeout;
}

var reqOpts = {
topic: this.name,
messages: messages
Expand Down
13 changes: 13 additions & 0 deletions packages/pubsub/test/topic.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,19 @@ describe('Topic', function() {
topic.publish(message, assert.ifError);
});

it('should honor the timeout setting', function(done) {
var options = {
timeout: 10
};

topic.request = function(protoOpts) {
assert.strictEqual(protoOpts.timeout, options.timeout);
done();
};

topic.publish(message, options, assert.ifError);
});

it('should send correct api request for raw message', function(done) {
topic.request = function(protoOpts, reqOpts) {
assert.deepEqual(reqOpts.messages, [
Expand Down

0 comments on commit 19ab795

Please sign in to comment.