From 6f96cb543fd53cd0f26b5b46738b14252d792b6a Mon Sep 17 00:00:00 2001 From: Burcu Dogan Date: Wed, 23 Jul 2014 15:22:05 -0700 Subject: [PATCH 1/2] Adding missing jsdocs. --- lib/pubsub/index.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/pubsub/index.js b/lib/pubsub/index.js index 5bbe480645a..ab96c967b5f 100644 --- a/lib/pubsub/index.js +++ b/lib/pubsub/index.js @@ -17,11 +17,19 @@ var conn = require('../common/connection.js'), util = require('../common/util.js'); -var PUBSUB_BASE_URL = 'https://www.googleapis.com/pubsub/v1beta1', - SCOPES = [ - 'https://www.googleapis.com/auth/pubsub', - 'https://www.googleapis.com/auth/cloud-platform' - ]; +/** + * Base URL for Pub/Sub API. + * @type {String} + */ +var PUBSUB_BASE_URL = 'https://www.googleapis.com/pubsub/v1beta1'; +/** + * Required scopes for Pub/Sub API. + * @type {Array} + */ +var SCOPES = [ + 'https://www.googleapis.com/auth/pubsub', + 'https://www.googleapis.com/auth/cloud-platform' +]; // TODO(jbd): Emit message and error events if in polled-mode. // sub.on('meessage', console.log) From 38bed993d58cf1b925e934369d446359b3f870f3 Mon Sep 17 00:00:00 2001 From: Burcu Dogan Date: Wed, 23 Jul 2014 15:23:04 -0700 Subject: [PATCH 2/2] Automatically acknowledging messages if autoAck is set. --- lib/pubsub/index.js | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/lib/pubsub/index.js b/lib/pubsub/index.js index ab96c967b5f..bd7a3b62d90 100644 --- a/lib/pubsub/index.js +++ b/lib/pubsub/index.js @@ -56,21 +56,31 @@ Subscription.prototype.ack = function(ids, callback) { /** * Pulls from the subscribed topic. - * @param {Boolean} returnImmediately If set, the system will respond immediately. - * Otherwise, wait until new messages are - * available. Returns if timeout is reached. - * @param {Boolean} autoAck Automatically acknowledges the - * backend after pulling. By default, true. - * @param {Function} callback Callback function. + * @param {Boolean} opts.returnImmediately If set, the system will respond immediately. + * Otherwise, wait until new messages are + * available. Returns if timeout is reached. + * @param {Boolean} opts.autoAck Automatically acknowledges the + * message once it's pulled. + * @param {Function} callback Callback function. */ Subscription.prototype.pull = function(opts, callback) { // TODO(jbd): Make opts optional. + var that = this; + var autoAck = !!opts.autoAck; var body = { subscription: this.name, returnImmediately: !!opts.returnImmediately }; - // TODO(jbd): Auto acknowledge. - this.conn.makeReq('POST', 'subscriptions/pull', null, body, callback); + this.conn.makeReq('POST', 'subscriptions/pull', null, body, function(err, message) { + if (err) { return callback(err); } + if (!autoAck) { + return callback(null, message); + } + that.ack(message.ackId, function(err) { + if (err) { return callback(err); } + callback(null, message); + }); + }); }; /**