Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Make non-value callbacks optional

  • Loading branch information...
commit d97090a41a77c699ce5e2a844c53290c10dd214c 1 parent 79f15a8
@pofallon authored
Showing with 44 additions and 4 deletions.
  1. +6 −0 lib/blob.js
  2. +18 −3 lib/queue.js
  3. +10 −0 lib/table.js
  4. +10 −1 lib/util.js
View
6 lib/blob.js
@@ -71,6 +71,8 @@ Container.listContainers = function(prefix, options, callback) {
Container.createContainer = function(name,options,callback) {
+ callback = skyutil.safeCallback(callback);
+
options.blobService.createContainerIfNotExists(name, function(err) {
if (err) {
callback(err);
@@ -83,6 +85,8 @@ Container.createContainer = function(name,options,callback) {
Container.removeContainer = function(name,options,callback) {
+ callback = skyutil.safeCallback(callback);
+
options.blobService.deleteContainer(name, function(err) {
if (err) {
callback(err);
@@ -231,6 +235,8 @@ Container.prototype.copy = function(b1,b2,callback) {
Container.prototype.del = function(name,callback) {
+ callback = skyutil.safeCallback(callback);
+
this.options.blobService.deleteBlob(this.name, name, function(err) {
if (err) {
callback(err);
View
21 lib/queue.js
@@ -68,6 +68,8 @@ Queue.listQueues = function(prefix, options, callback) {
Queue.createQueue = function(name,options,callback) {
+ callback = skyutil.safeCallback(callback);
+
options.queueService.createQueueIfNotExists(name, function(err) {
if (err) {
callback(err);
@@ -80,6 +82,8 @@ Queue.createQueue = function(name,options,callback) {
Queue.removeQueue = function(name,options,callback) {
+ callback = skyutil.safeCallback(callback);
+
options.queueService.deleteQueue(name, function(err) {
if (err) {
callback(err);
@@ -91,6 +95,8 @@ Queue.removeQueue = function(name,options,callback) {
};
Queue.prototype.put = function(message,callback) {
+
+ callback = skyutil.safeCallback(callback);
this.options.queueService.createMessage(this.name, message, function(err) {
if (err) {
@@ -130,11 +136,18 @@ Queue.prototype.del = function(id,receipt,callback) {
// Support passing in a message to delete,
// rather than its individual components
- if ((arguments.length === 2) && ((typeof id) === "object")) {
- receipt = id.popreceipt;
- id = id.messageid;
+ if (arguments.length < 3) {
+ if ((typeof receipt) === 'function') {
+ callback = receipt;
+ }
+ if ((typeof id) === "object") {
+ receipt = id.popreceipt;
+ id = id.messageid;
+ }
}
+ callback = skyutil.safeCallback(callback);
+
this.options.queueService.deleteMessage(this.name, id, receipt, function(err) {
if (err) {
callback(err);
@@ -147,6 +160,8 @@ Queue.prototype.del = function(id,receipt,callback) {
Queue.prototype.clear = function(callback) {
+ callback = skyutil.safeCallback(callback);
+
this.options.queueService.clearMessages(this.name, function(err) {
if (err) {
callback(err);
View
10 lib/table.js
@@ -74,6 +74,8 @@ Table.listTables = function(prefix,options,callback) {
Table.createTable = function(name,options,callback) {
+ callback = skyutil.safeCallback(callback);
+
options.tableService.createTableIfNotExists(name, function(err) {
if (err) {
callback(err);
@@ -86,6 +88,8 @@ Table.createTable = function(name,options,callback) {
Table.removeTable = function(name,options,callback) {
+ callback = skyutil.safeCallback(callback);
+
options.tableService.deleteTable(name, function(err) {
if (err) {
callback(err);
@@ -98,6 +102,8 @@ Table.removeTable = function(name,options,callback) {
Table.prototype.del = function(partition,row,callback) {
+ callback = skyutil.safeCallback(callback);
+
this.options.tableService.deleteEntity(this.name, {PartitionKey:partition, RowKey:row}, function(err) {
if (err) {
callback(err);
@@ -114,6 +120,8 @@ Table.prototype.update = function(partition,row,elem,opts,callback) {
callback = opts;
}
+ callback = skyutil.safeCallback(callback);
+
var entity = u_.clone(elem);
entity.PartitionKey = partition;
entity.RowKey = row;
@@ -158,6 +166,8 @@ Table.prototype.insert = function(partition,row,elem,callback) {
entity = u_.clone(elem);
break;
}
+
+ callback = skyutil.safeCallback(callback);
entity.PartitionKey = partition;
entity.RowKey = row;
View
11 lib/util.js
@@ -6,6 +6,14 @@
var EventEmitter = require('events').EventEmitter;
+var safeCallback = function(cb) {
+ if ((typeof cb) === 'function') {
+ return cb;
+ } else {
+ return function() {};
+ }
+}
+
var prepFetch = function(args, callback) {
// prefix, options, callback, doFetch
@@ -47,4 +55,5 @@ var prepFetch = function(args, callback) {
}
-exports.prepFetch = prepFetch;
+exports.prepFetch = prepFetch;
+exports.safeCallback = safeCallback;
Please sign in to comment.
Something went wrong with that request. Please try again.