How can I tell when all of the asynchronous calls on my page have finished (Parse Cloud functions)?

Henry

I have a couple functions that make multiple delete calls to social media APIs, and I need to know when all of them are finished. I'm using Parse Cloud Code to make these calls, and I'm not sure if they use AJAX. I tried the ajaxStop method as described here: Waiting on multiple asynchronous calls to complete before continuing but nothing came up. I did a simple

$(document).ajaxStart(function(){
   console.log("ajax calls started");
});

but nothing came up in my console for that either.

$('#delete').click(function(){

    $(function(){
        $(document).ajaxStop(function(){
            $(this).unbind("ajaxStop");
            console.log("All calls finished");          
        });
        deleteTwitter();
        deleteTumblr();
    });

});

I'm not sure how else to go about this, also, NodeJS isn't an option. I'd really appreciate some insight on this, whether it's knowledge about Parse Cloud Code or just something I'm misunderstanding about how AJAX works. Thank you.

Henry

Thanks to @Fosco for pointing me towards Promises. I just created a custom promise each time I made a call, and used Parse.Promise.when() to execute code when all promises are fulfilled.

var promiseArray = [];
deleteSomething();

Parse.Promise.when(promiseArray).then(function(){
    //triggers when all promises fulfilled
    console.log("All delete calls completed");
});

//------------------------------------------------
function deleteSomething()
{
    var promise = new Parse.Promise;
    promiseArray.push(promise);

    Parse.Cloud.run('foo', {...}, {
        success(): function(){ promise.resolve("Call finished");},
        error():{promise.reject("Call failed");}
    });
}

See here http://www.parse.com/docs/js/symbols/Parse.Promise.html for a more detailed explanation of promises.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do I know when all AJAX calls from a particular functions are finished?

How can I avoid bundlers warning about multiple sources when I have all gems in my .gemspec?

Magento - How can I tell if I'm on a "My Account" page?

python multiprocessing pool: how can I know when all the workers in the pool have finished?

How to know when all Angular2 HTTP calls are finished

How can I tell that the page has finished loading?

How do I tell when a NetworkImage has finished loading?

How can I tell if my promise.all is running in parallel?

How to know if asynchronous calls are finished? (HackerNews Comments)

How can I change the priority for calls in my parse server in javascript?

How should I handle asynchronous calls when initializing my BLoC?

How can I tell when Blazor has finished rendering a DOM element?

How can I tell when documents have been indexed?

How can I tell when a Layout (and all its child Views) has fully finished inflating?

Whay do my divs move down on the page when there they have text in them and how can I fix this?

How can I tell when my file system was last fsck-ed at all?

How can I tell when Rules have finished processing?

How can I know when Ajax calls are finished with getScript?

How to tell activity that fragments are finished with network calls

In my code, only one link is parse, but I have four different links. How can I parse all of them

How can I call a function only once all requests have finished?

Django: How can i do annotate just when all my models have some value

How can I pass data loaded when my application finished launching thru my UITabBar to a UITableView?

How can I make my functions to have edges?

How can I run a callback when I know all asynchronous calls have been completed?

Unable to cleanup useEffect, how can I cancel all asynchronous tasks when unmounting my component?

How can I autowire my beans in Spring Cloud Functions in Azure?

How can I tell when my code has been reflected?

How can I block and wait until an asynchronous StreamObserver call is finished?