Skip to content

Commit

Permalink
Azure#4: Fixing concurrency issue with batch commits.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andre Rodrigues committed Dec 13, 2011
1 parent ac7e5b7 commit 52148ce
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions lib/services/table/batchserviceclient.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,17 @@ BatchServiceClient.prototype.commitBatch = function (optionsOrCallback, callback
webResource.addOptionalHeader(HeaderConstants.CONTENT_LENGTH, body.length);

var self = this;

// Store current operations to process response
// and clear batch operation to end isInBatch state after commiting
var requestOperations = this.operations;
this.operations = null;

var processResponseCallback = function (responseObject, next) {
var responseObjects = self.processResponse(responseObject);
var responseObjects = self.processResponse(responseObject, requestOperations);
responseObject.operationResponses = responseObjects;

var finalCallback = function (returnObject) {
// clear batch operation, on the final callback, to end isInBatch state after commiting
self.operations = null;

// perform final callback
callback(returnObject.error, returnObject.operationResponses, returnObject.response);
};
Expand All @@ -171,7 +174,7 @@ BatchServiceClient.prototype.commitBatch = function (optionsOrCallback, callback
* @param {object} responseObject The response object for the batch request.
* @return An array with the processed / parsed responses.
*/
BatchServiceClient.prototype.processResponse = function (responseObject) {
BatchServiceClient.prototype.processResponse = function (responseObject, requestOperations) {
var responses = null;
if (responseObject && responseObject.response && responseObject.response.body) {
responses = [];
Expand All @@ -184,7 +187,7 @@ BatchServiceClient.prototype.processResponse = function (responseObject) {
if (httpLocation !== -1) {
var rawResponse = rawResponses[i].substring(httpLocation);
// valid response
var response = this.processOperation(this.operations[validResponse++].webResource, rawResponse);
var response = this.processOperation(requestOperations[validResponse++].webResource, rawResponse);
responses.push(response);
}
}
Expand Down

0 comments on commit 52148ce

Please sign in to comment.