the Reverend
the Reverend

Reputation: 12549

Azure Mobile Services Api Global Variables Scope

I have a custom api on my Mobile Service that looks like some variables are getting overridden when 2 users call it at the same time.

I'm calling the script by the "POST" method. Below I show the initial part of the script. Can some one give me more information on the scope of the variables defined at the top ? Could it be possible that 2 users be using the same variables ?

var tableArray = null;
var requestObject = null;
var responseObject = null;
var accountFunctions = null;
var userID = 0;
var serverSyncTimeStamp = 0;
var clientSyncTimeStamp = 0;
var random = 0;
var start = null;
var time  = null;

exports.post = function(request, response) {
    if (request.query.userID === null) {
        response.send(statusCodes.BAD_REQUEST,'did not supply a userID');
        return;
    }


    start = new Date().getTime();
    cleanUp();
    accountFunctions = require('../shared/accountFunctions.js');
    random = Math.random();
    userID = Number(request.query.userID);
    ETC ETC ETC ..........

Upvotes: 1

Views: 193

Answers (1)

phillipv
phillipv

Reputation: 1717

For Custom API's, the global scope is shared between all executions. (Unlike with table scripts, where each script execution has its own global scope)

So yes, each time a POST to your API happens, they will modify the same set of variables.

Upvotes: 1

Related Questions