1

I have such code on parse cloud code file

Parse.Cloud.define("updateUserRatings", function (request, response) {

    var query = new Parse.Query("Table");

    query.find({
        success: function (users) {
            number1();
            number2();
            number3();
            number4();
            number5();
            response.success("success");
        },
        error: function () {
            response.error("error");
        }
    });


});

function number1 () {
    console.log("number1");
}

function number2 () {
    console.log("number2");
}

function number3 () {
    console.log("number3");
}

function number4 () {
    console.log("number4");
}
function number5 () {
    console.log("number5");
}

In logs it must looks like that

number1
number2
number3
number4
number5

but I see that

I2014-08-08T12:57:42.370Z] v24: Ran cloud function updateUserRatings with:
  Input: {}
  Result: success
I2014-08-08T12:57:42.510Z] number3
I2014-08-08T12:57:42.513Z] number5
I2014-08-08T12:57:42.514Z] number1
I2014-08-08T12:57:42.514Z] number2
I2014-08-08T12:57:42.514Z] number4

why it invoked in wrong order? That messed all. I can not create right code, because it invokes in random order. Why is that?

1
  • Well, while logging, queries and network handling is asynchronous, the rest of code should work fine in general. Commented Aug 8, 2014 at 13:36

1 Answer 1

2

This is a known phenomenon -- Parse collects console log entries in an asynchronous way, so there is no guarantee that the order they appear in the log represents the order they were executed. the execution itself should be happening in an entirely consistent, predictable, synchronous way -- i've never noticed any problems with that.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.