Do we need to close the response object if an error occurs while calling http.Get(url)?

General concept is that when a function (or method) has multi return values one being an error, error should be checked first and only proceed if the error is nil. Functions should return zero values for other (non-error) values if there is an error. If the function behaves differently, it should be documented. http.Get() does … Read more

jQuery Deferred – getting result of chained ajax calls

If you know how many Ajax-Calls you have, simply use $.when() $.when(doAjax(‘a’),doAjax(‘b’),doAjax(‘c’),doAjax(‘d’)) .then(function(result_a,result_b,result_c,result_d) { console.log(“Result from query a: ” + result_a); console.log(“Result from query b: ” + result_b); console.log(“Result from query c: ” + result_c); console.log(“Result from query d: ” + result_d); }); If you don’t know how many ajax-calls you will have, you can … Read more

AngularJS $q. Deferred queue

Don’t use a queue and that boolean flag, just have one variable storing a promise representing all uploads. Also, your upload function should not take a Deferred object to resolve as an argument, but simply return a new promise. Then the addAnUpload becomes as simple as var allUploads = $q.when(); // init with resolved promise … Read more

How to chain ajax calls using jquery

With a custom object function DeferredAjax(opts) { this.options=opts; this.deferred=$.Deferred(); this.country=opts.country; } DeferredAjax.prototype.invoke=function() { var self=this, data={country:self.country}; console.log(“Making request for [” + self.country + “]”); return $.ajax({ type: “GET”, url: “wait.php”, data: data, dataType: “JSON”, success: function(){ console.log(“Successful request for [” + self.country + “]”); self.deferred.resolve(); } }); }; DeferredAjax.prototype.promise=function() { return this.deferred.promise(); }; var countries … Read more