deferred

jquery custom deferred functions

别等时光非礼了梦想. 提交于 2019-12-03 03:54:58
问题 I have three functions i'm trying to run, the first two are doing some async stuff that need data for the third to use. I want the third function to fire only when 1 and 2 are both done. this is the general structure but the final function is firing before 1 and 2 finish. function run() { var data1 = {}; var data2 = {}; $.when(first(), second()).done(constructData()); function first() { var d = new $.Deferred(); //do a bunch of stuff async data1 = {}; d.resolve(); } function second() { var d

attempting to break jQuery promise chain with .then, .fail and .reject

半城伤御伤魂 提交于 2019-12-03 02:28:19
Update: this issue was a result of jQuery 1.7 vs 1.8. Do not ever use promises in 1.7 beacuse they aren't chainable with returning a promise inside a .then . 1.8 looks like they didn't mess it up. http://jsfiddle.net/delvarworld/28TDM/ // make a promise var deferred = $.Deferred(); promise = deferred.promise(); // return a promise, that after 1 second, is rejected promise.then(function(){ var t = $.Deferred(); setTimeout(function() { console.log('rejecting...'); t.reject(); }, 1000); return t.promise(); }); // if that promise is successful, do this promise.then(function() { console.log('i

How does Angular $q.when work?

自古美人都是妖i 提交于 2019-12-03 02:06:44
问题 Can some one explain me how does $q.when work in AngularJS? I'm trying to analyse how $http work and found this: var promise = $q.when(config); And here is config object from Chrome console: Object {transformRequest: Array[1], transformResponse: Array[1], cache: Object, method: "GET", url: "/schedule/month_index.html"…} cache: Object headers: Object method: "GET" transformRequest: Array[1] transformResponse: Array[1] url: "/schedule/month_index.html" __proto__: Object What happens next? How

JavaScript naming convention for promises? [closed]

一个人想着一个人 提交于 2019-12-03 00:54:11
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. I feel it would be useful to have a naming convention for JavaScript variables which hold a promise . I don't generally like or advocate naming conventions beyond programming language standards, but in the style of programming where promises are passed

Implement Deferred object without using jquery

*爱你&永不变心* 提交于 2019-12-03 00:28:56
I want to implement basic Deferred object without using jQuery. Here i will be implementing only done and fail callbacks, with resolve and reject functions. and ofCourse associating promise method with this function. i am doing the following implementation in pure js (Edited) : function Deferred() { var d = {}; d.resolve = function() { d.done(arguments); } d.reject = function() { d.fail(arguments); } d.promise = function() { var x = {}; x.done = function(args) { return args; } x.fail = function(args) { return args; } return x; } return d; } var v; var setVal = function() { var d = new Deferred

Difference between Spring MVC's @Async, DeferredResult and Callable

a 夏天 提交于 2019-12-02 19:02:40
I've a long-running task defined in a Spring service. It is started by a Spring MVC controller. I want to start the service and return back an HttpResponse to the caller before the service ends. The service saves a file on file system at end. In javascript I've created a polling job to check service status. In Spring 3.2 I've found the @Async annotation, but I don't understand how it is different from DeferredResult and Callable . When do I have to use @Async and when should I use DeferredResult ? Async annotates a method so it is going to be called asynchronously. @org.springframework

Dynamic multiple Deferred jQuery Ajax calls

柔情痞子 提交于 2019-12-02 19:00:35
Using the Deferred pattern from jQuery http://api.jquery.com/jQuery.when/ , I am trying to make multiple jsonp ajax calls and wait for the results before moving to the next step. I can accomplish this using a fixed amount of calls because I can set the number of resolved argument parameters in the ".done()" deferred object. But in my application it doesn't work because the number of calls is dynamic and always unknown. This first simplified example works because I can set the number of args in the .done() resolved function. I know I need two because there are two calls in the .when(): $.when(

How does Angular $q.when work?

一曲冷凌霜 提交于 2019-12-02 15:41:38
Can some one explain me how does $q.when work in AngularJS? I'm trying to analyse how $http work and found this: var promise = $q.when(config); And here is config object from Chrome console: Object {transformRequest: Array[1], transformResponse: Array[1], cache: Object, method: "GET", url: "/schedule/month_index.html"…} cache: Object headers: Object method: "GET" transformRequest: Array[1] transformResponse: Array[1] url: "/schedule/month_index.html" __proto__: Object What happens next? How this object get's resolved or rejected? Calling $q.when takes a promise or any other type, if it is not

How to determine that all the files have been read and resolve a promise

时光总嘲笑我的痴心妄想 提交于 2019-12-02 09:17:32
问题 The following code is responsible for reading files. My requirement is how to find whether all files has been read so that I can return or resolve a promise from the parent function(readmultifiles). $.when(readmultifiles(files)) .then(function(){//all files uploaded})) Above code initiates the file read. What can be done so that upon reading of all files callback is done or a return can be made. function readmultifiles(files) { // Read first file setup_reader(files, 0); } function setup

How to determine that all the files have been read and resolve a promise

大憨熊 提交于 2019-12-02 04:37:23
The following code is responsible for reading files. My requirement is how to find whether all files has been read so that I can return or resolve a promise from the parent function(readmultifiles). $.when(readmultifiles(files)) .then(function(){//all files uploaded})) Above code initiates the file read. What can be done so that upon reading of all files callback is done or a return can be made. function readmultifiles(files) { // Read first file setup_reader(files, 0); } function setup_reader(files, i) { var file = files[i]; var name = file.name; var reader = new FileReader(); reader.onload =