Search code examples
javascriptparse-platformparse-cloud-code

get response from cloud function inside another one


I have in my cloud code this two functions What I'm trying to do is calling one function from another one (hello from count). The problem is the success block in the run function isn't executed and the console remain silent. What to do ?

Count Function :

Parse.Cloud.define('count', function(request, response) {

var query = new Parse.Query('MyClass');
  query.find({
    success: function(results) {

      Parse.Cloud.run('hello', {}, {
       success: function(result) {
         console.log('What is the result ? ' + result);
       },
       error: function(error) {
       }
       });
      response.success(results);
    },
    error: function(error) {
      response.error(error);
    }
  });
});

Hello Function :

Parse.Cloud.define('hello', function(request, response) {
 response.success("Hello world!");
});

Solution

  • This is because your hello function is executed asynchronously but before it finishes, your code already has hit response.success(results);. You either need to move the response.success(); to your hello success block or you need to use Promises.