2

This question is simple, but I didn't find it already asked ... Is there a way to cancel a Parse cloud function callback ?? I'm developing an app, where it would be great to ignore (or even better, not receive at all) the callback of a cloud function given certain events (like a log out).

I'm using cloudCode to retrieve an user New Messages, I'm doing that asynchronously. I would have to cancel that request if a user logs out, to avoid having the new messages from a user that is no longer logged in.

I've seen that, for example, on a PFQuery where we have a "Cancel" method to avoid the callback of the query, also for PFFiles there is a "cancel", but did not see anything like this for cloud functions .

Is there a way to do this ? to cancel the cloudCode request??

EDIT: Here the Objective-C code I'm using to call the function

[PFCloud callFunctionInBackground:"getNewMessages" withParameters:@{} block:^(id object, NSError *error) {
    if (!error) {
      NSArray *newMessages = (NSArray *)object;
      NSLog(@"*** %lu NEW MESSAGES FOUND", (unsigned long)newMessages.count);
    } else {
      NSLog(@"*** ERROR getting new messages: %@", error);
    }
}];

And this is the function in cloudCode

Parse.Cloud.define("getNewMessages", function(request, response) {
    var newMessagesQuery = new Parse.Query("Messages");
    newMessagesQuery.equalTo("receiver", request.user);
    newMessagesQuery.descending("createdAt");    
    newMessagesQuery.find().then(function(myNewMessages) {
            response.success(myNewMessages);
        },function(error) {
            console.error("Error getting new messages");
            response.success(error);
        });
});

Thanks!

Esteban Vallejo
  • 697
  • 1
  • 5
  • 11
  • It's unclear what you want to do. Do you want to cancel the request or do you want to ignore the callback? What exact function are you using? Show us some code and we can help. – KerrM Nov 17 '14 at 13:48
  • @KerrM - Thanks for the answer, I have just edited the question and added both Objective-C and JS code. It would be great to be able to cancel the ongoing request, if that's not posible, then try to ignore the callback. – Esteban Vallejo Nov 17 '14 at 14:07

0 Answers0