FAQ Database Discussion Community


jQuery Deferred / Promise

javascript,jquery,arrays,promise,deferred
I'm trying to use deferred/promise in a loop, but I get strange behavior. My code is as follows: var images = []; var numImages = Blobs.length; var image = {}; console.log("numImages: " + numImages); function doAsyncOriginal(i) { var defer = $.Deferred(); image.original = Blobs[i].key; image.resized = ''; image.thumbnail = '';...

JQuery - Calling function after image load

javascript,jquery,image,load,deferred
So I have two functions. One to load the image and the other to resize its container element. Naturally the image element needs to be loaded, before any measurements can be taken. It looks something like this: var imgEl; loadImage(imgSrc); // only call the below, once the above has finished...

jQuery deferred - when multiple timeout tasks have completed

javascript,jquery,jquery-deferred,deferred,.when
Having a few teething problems with $.deferred, $.when and $.done. I'm calling a method which has a couple of tasks inside on a timer. I'm looking at getting a callback when everything inside this method has completed, including the stuff in timers, so started looking at $.when() and $.done() to...

Understanding the syntax of a deferred execution chain

javascript,node.js,deferred
I'm getting around to learning JavaScript - really learning JavaScript. I come from a PHP background so some JavaScript concepts are still new to me, especially asynchronous programming. This question might have already been answered many times before but I have not been able to find an answer. It might...

Behavior on AngularJS deferred object

ajax,angularjs,deferred,angular-promise
I was writing a function that will be executed asynchronously. Suddenly a question popped up in my mind. Let's say I have the following function for updating student records. module.factory('StudentService', function($http, $q) { var service = {}; service.updateStudent = function(studentData) { var deferred = $q.defer(); $http.put('http://www.example.com/student/update', studentData, { headers: {...

Is there idiomatic scoped sematics in golang?

go,deferred,idiomatic,scoped-lock
I wonder if there is any idiomatic way to represent scoped sematics. By scoped I mean things like: scoped mutex (oneliner instead of explicit Lock + deffered Unlock), logging function (or any code block) entrance and exit, measuring execution time. Example code for first two bullets: package main import "log"...

Twisted callback loop blocking further data from being recieved

python,callback,twisted,deferred
When a callback loop is running in Twisted, it was my impression that the reactor was still able to send/receive data from the server, as it was able to function 'between' the callbacks. However, when I run the script below, it entirely ignores the self.transport.write() line. The server is just...

What does @defer.inlineCallbacks mean when I don't need yield return a value?

python,scrapy,deferred
At scrapy.core.engine ExecutionEngine method start @defer.inlineCallbacks def start(self): """Start the execution engine""" assert not self.running, "Engine already running" self.start_time = time() yield self.signals.send_catch_log_deferred(signal=signals.engine_started) self.running = True self._closewait = defer.Deferred() yield self._closewait Why don't use self.signals.send_catch_log_deferred(signal=signals.engine_started) directly but instead of a yield ?...

How to test .notify for .then in angularjs

javascript,angularjs,deferred,angular-promise
In this post function var deferredRespond = $q.defer(); var statusNotice="Loading..."; deferredRespond.notify(statusNotice); $http.post(processorUrl,{ params:request, }).success(function(respondData){ //deferredRespond.resolve(respondData); /*For Test Rejected Defer! -awh*/ deferredRespond.resolve($q.reject("Simulated Reject")); //deferredRespond.resolve($q.notify("Simulated LOADING...")); }) .error(function(){ deferredRespond.reject('Failed defer!'); }); I am able to simulate .reject by doing .resolve($q.reject But I wonder why I can not...

How can I return the value of a deferred method in javascript

javascript,dojo,deferred,arcgis-js-api
I am trying to write a module which projects coordinates into a new Spatial Reference, but the javascript syntax has beaten me once again. This is how the module currently looks like: define(["esri/geometry/Point", ...], function(Point, SpatialReference, ...){ var gmsvc = new GeometryService("http://server/maps/rest/services/Utilities/Geometry/GeometryServer"); /*...*/ return { /*...*/ //transforms the current point...

Angular Promise Called Twice is Only Deferring to First Caller

angularjs,jsonp,deferred,angular-promise,angular-services
I'm working on a video series app that's set up like so: angular.module('videoSeries', ['ngAnimate', 'ui.router']) .config(config) .factory('episodes', episodesFactory) .controller('MainCtrl', MainCtrl) .controller('EpisodeCtrl', EpisodeCtrl); The factory 'episodes' loads a JSONP file that both controllers need to read from. In order to ensure that the controllers wait until the JSONP has successfully returned,...

Error is not thrown inside a deferred method

node.js,exception-handling,deferred
Can somebody explain to me why my error is not thrown in my first example? And why it is when I use process.nextTick() ? var deferred = require('deferred'); // This code does not work. // Error seems to never been thrown and script kind of freeze without saying anything. deferred.resolve().then(function(){...

Return list item id using deferred

jquery,sharepoint,deferred
how can I return value using code like below? I need to assign the value to any variable. It works with alerts. But I need to retrieve value. function getLookupIDValue(criterium, list) { var promise = execCamlQuery(criterium, list); var value; promise.done( function (criteriumCollectionListItem) { var criteriumListItemEnumerator = criteriumCollectionListItem.getEnumerator(); while (criteriumListItemEnumerator.moveNext()) {...

jQuery .when().done() not working

jquery,deferred
I'd like to start by saying I'm new to jQuery and I suspect I'm just doing something stupid, so hopefully this will be very simple for someone. I'm trying to add a sliding mobile sub-menu to my website. I want an accordian effect whereby if I click one parent link,...

jQuery deferred queue in for loop

javascript,jquery,ajax,deferred
I have the following function: function getData(a,url) { var deferreds = []; var i = 1; for (i = 1; i <= a.length; i++) { var count = i; var back = a[i]['link']; var path = "http://example.com"; deferreds.push( $.ajax({ url:path, data:{back:back,link:url}, type:"POST", async: true, delay: count }).done(function(data) { //success function...

How can I make a waterfall Q promises?

javascript,angularjs,promise,q,deferred
let's take this as an example: I have 3 urls in an array urls require function returns a promise which just makes an $http call this is a working code, but as the array can be '1 to n' this is obviously not what I want. I need the 3...

How do I use RSVP deferreds with WebSocket?

javascript,websocket,deferred,rsvp.js
I need to open multiple WebSocket connections concurrently and then perform actions once all the connections are opened. I am using the defer(), all(), and then() methods of RSVP.js. However, neither the then() nor the catch() is being triggered, and I cannot figure out where I am going wrong. Here...

how to build a chain of calls render itemViews in marrionete.js deferred with async function inside itemView

javascript,jquery,callback,marionette,deferred
I have a very simple structure ProductsList.TileListView = Marionette.CollectionView.extend({ tagName: 'section', className: 'b-list-viewtile', template: '/static/js/app/list/modules/productslist/templates/tileList', childView: ProductsList.TileItemView }); ProductsList.TileItemView = Marionette.ItemView.extend({ tagName: "article", className: "b-list-viewtile__item", template: '/static/js/app/list/modules/productslist/templates/tileItem', _getImage: function(){ var _this = this; var img = new Image(); img.src =...

deferred object returning before resolving

javascript,node.js,promise,deferred,when-js
I am using the when library with Node js. I create a deffered object, place the resolve inside an encapsulated Mongoose findOne() function, and return the promise outside. But it seems my promise is always returned before the data is retrieved. User.prototype.getProfile = function(criteria) { var deferred = when.defer(); var...