Skip to main content

Using RSVP for multiple ajax promises

So i was working on a bug in my project the other day wherein the requirement so we had to make multiple ajax calls to our backend and then once when “all were done” we had to trigger the success callback, even if any one of the calls fails we do not trigger the success callback. And the asynchronus nature of the the ajax calls make it more difficult.


So to solve this problem we had a count variable with a promise, with every callback we were incrementing the callback and then when the count was equal to the number of calls then we would resolve the deffered object which would fire the success callback. This approach worked but was difficult to understand and debug.



To simplify this a bit we used the RSVP which was bundled with the ember source. so instead of maintaining the count and then manually resolving the promise we used the Ember.RSVP.all(<array to observe>, function(){ console.log(“success callback”)})
so it resolves the success callback once all the promises which are present in the array are resolved. So it makes it simple for someone to comprehend the solution. Though we could have written a similar thing , but why solve a problem which has already been solved before ;-)



you can read about the Ember.RSVP at http://emberjs.com/api/classes/Ember.RSVP.Promise.html#sts=Ember.RSVP.Promise Class packages/rsvp/lib/main.js:950

Comments

Popular posts from this blog

Fractals and Mandelbrot Set

While mathematics is in itself quite interesting and forms the basis of any modern day research, be it computational biology, machine learning or building complex structure, it can be quite a challenge to decide where to start.  That is why i decided to explore Fractals, thinking of it as a bridge between the nature and science. It brings in some really fascinating concepts which should be good enough for me as a gateway go deeper.  Fractals are in simple language never ending patterns which keep on repeating without an end, because fractals are never ending they have an infinite perimeter but finite area.  Since the patterns repeats indefinitely but if you draw a circle around the peremeter the area will remain finite.  It is like adding 1+0.1+0.01+0.001 and never making 2 This video explains the basic concept really well  Fractals are found everywhere nature in Trees, Rivers, Branching patterns, Hurricanes and Galaxies. It tries to bring order and understanding to the patterns that w
It was a great experience to talk to a huge audience in Mumbai and Delhi about how to start your ML journey at Google Cloud Summit ’18 India

COVID-19 Lockdown

It is May 11th 2020 and most of India has been under lockdown for 46 straight days. These have been tough times for everyone. While some of the folks i know have been cribbing about being bored to death in this lockdown, for me it has been a busy time. My current field of work which is "Cloud Technology" picked up as everyone was locked up with nothing but technology to entertain and survive and hence there was a lot of work. While me and my family was trying to navigate the chaos and madness of ordering everything online, i would say we were able to deal with the situation without going out much.  This was until my phone broke, crashed, bricked, it was gone.  While i had a spare 4 year old iPhone to fall back on but you know about spare phones, they were too old to trade for a newer one is why you decided to label it as a spare and keep it. They almost never work. So after struggling to get my office and personal stuff to work on an old phone and tablet, i decided i needed t