Skip to content

Commit

Permalink
Added a promise and alt syntax version of listQueues.
Browse files Browse the repository at this point in the history
  • Loading branch information
dmohl committed Nov 8, 2013
1 parent 797e1b4 commit 0972c5b
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 17 deletions.
42 changes: 41 additions & 1 deletion dist/fogjs.js
Expand Up @@ -809,14 +809,54 @@ exports.getQueue = function (serviceBusOrAllParams, queuePath, options) {
if (serviceBusOrAllParams && serviceBusOrAllParams.queuePath) {
queuePath = serviceBusOrAllParams.queuePath;
options = serviceBusOrAllParams.options;
getTheQueue(defaultServiceBus);
exports.createQueueIfNotExists(serviceBusOrAllParams)
.then(function() {
getTheQueue(defaultServiceBus);
});
} else {
getTheQueue(serviceBusOrAllParams);
}

return deferred.promise;
};

// This is similar to the same as the Azure API function with the same name; however, it uses promises instead of callbacks.
// If there is an error, then a new Error is created with the original error text and included as the argument to the reject call.
// If no error message is returned, then a listQueuesResult and a response is returned.
exports.listQueues = function (serviceBusOrAllParams, options) {
var deferred = q.defer();
var callback = function(error, listQueuesResult, response) {
if (error) {
deferred.reject(new Error(error));
} else {
var result = {
"listQueuesResult" : listQueuesResult,
"response" : response
};
deferred.resolve(result);
}
};

var listTheQueues = function(serviceBus) {
if (options) {
serviceBus.listQueues(options, callback);
} else {
serviceBus.listQueues(callback);
}
};

if (!serviceBusOrAllParams || (serviceBusOrAllParams && serviceBusOrAllParams.options)) {
if (serviceBusOrAllParams && serviceBusOrAllParams.options) {
options = serviceBusOrAllParams.options;
}
listTheQueues(defaultServiceBus);
} else {
listTheQueues(serviceBusOrAllParams);
}

return deferred.promise;
};

module.exports = exports;
;var q = require("q");
var azure = require("azure");
Expand Down

0 comments on commit 0972c5b

Please sign in to comment.