deferred

Twisted: how to get error parameters from failure?

天涯浪子 提交于 2020-01-04 05:55:36
问题 I have a piece of code: from twisted.web.client import getPage from twisted.internet import reactor class TestError(Exception): def __init__(self, message): self.message = message def __repr__(self): return 'TestError' def gotPage(response): print response reactor.stop() def gotErr(failure): raise TestError('This is error') def newEb(failure): try: failure.raiseException() except TestError as te: print te.message reactor.stop() if __name__ == '__main__': deferred = getPage('http://somebadpage

jQuery - Deferreds waiting for an array of ajax requests to complete even failures

心已入冬 提交于 2020-01-03 15:58:03
问题 How can execute a function after a number of ajax requests have all completed regardless of whether they succeeded or error-ed out? I've been trying to use $.when.apply(this, array) to pass an array of deferred jqXHR objects. However just like the docs say In the multiple-Deferreds case where one of the Deferreds is rejected, jQuery.when immediately >fires the failCallbacks for its master Deferred. Note that some of the Deferreds may still be >unresolved at that point. How can leverage jQuery

jQuery - Deferreds waiting for an array of ajax requests to complete even failures

回眸只為那壹抹淺笑 提交于 2020-01-03 15:56:09
问题 How can execute a function after a number of ajax requests have all completed regardless of whether they succeeded or error-ed out? I've been trying to use $.when.apply(this, array) to pass an array of deferred jqXHR objects. However just like the docs say In the multiple-Deferreds case where one of the Deferreds is rejected, jQuery.when immediately >fires the failCallbacks for its master Deferred. Note that some of the Deferreds may still be >unresolved at that point. How can leverage jQuery

Is Twisted's Deferred the same as a Promise in JavaScript?

两盒软妹~` 提交于 2020-01-01 01:55:33
问题 I started using Twisted in a project that require asynchronous programming and the docs are pretty good. So my question is, is a Deferred in Twisted the same as a Promise in Javascript? If not, what are the differences? 回答1: The answer to your question is both Yes and No depending on why you're asking. Yes: Both a Twisted Deferred and a Javascript Promise implement a mechanism for queuing synchronous blocks of code to be run in a given order while being decoupled from other synchronous blocks

Q.js - Using deferred

狂风中的少年 提交于 2020-01-01 01:55:11
问题 How do I get the value of the text from the example below? Q.js has an example on using Deferred: var deferred = Q.defer(); FS.readFile("foo.txt", "utf-8", function (error, text) { if (error) { deferred.reject(new Error(error)); } else { deferred.resolve(text); } }); return deferred.promise; In this case, there is a node async function being used. What I want to do is get the value of text from the deferred.promise being returned. When I console.log(deferred.promise) I get this: { promiseSend

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

天涯浪子 提交于 2019-12-31 21:30:20
问题 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

Google is wrong about defer?

允我心安 提交于 2019-12-31 02:43:12
问题 In this post: Why google is using the term "Render-Blocking JavaScript"? @jaffa-the-cake is asking in a comment to someone: "Which piece of documentation do you consider incorrect?" Let's take for example this documentation: https://developers.google.com/speed/docs/insights/BlockingJS And now let's take for example what they are saying about "defer": The loading and execution of scripts that are not necessary for the initial page render may be deferred until after the initial render or other

Recovering from rejected promises in JS

不羁的心 提交于 2019-12-31 01:13:54
问题 I'm using native promises (mostly) and attempting to recover from an error and continue executing the promise chain. Effectively, I'm doing this: REST query to see if ID exists. Note that this returns a jquery deferred. .then (success means ID exists, so fail and stop) (fail means ID does not exist, so continue creating ID) .then (create the ID record and send to the server) I return a Promise.resolve() from my rejected function, which should cause the success part of the next .then to

Using jQuery.Deferred to avoid nested setTimeout callbacks

南笙酒味 提交于 2019-12-30 22:59:48
问题 setTimeout -> console.log 'foo' setTimeout -> console.log 'bar' setTimeout -> console.log 'baz' , 1000 , 1000 , 1000 Is it possible to achieve the same result with jQuery.Deferred? Something like the following, perhaps: someFunction() .then(-> console.log 'foo') .then(delay 1000) .then(-> console.log 'bar') .then(delay 1000) .then(-> console.log 'baz') Perhaps I'm wrong in thinking promises make it easy to write: Do A, then once that finishes, do B, then once that finishes, do C . 回答1: You

How to know when a recursive, asynchronous task finishes

£可爱£侵袭症+ 提交于 2019-12-30 10:04:18
问题 I have a async function, which can recurse into itself. I'm adding jQuery deferreds to an array each time the function runs, an use $.when() to check if all promises have resolved. My issue is that I can't seem to do this without an arbitary timeout, as I simply don't know when the function stops recursing and adding new promises. Here's a JSBin demonstration. And here's the real world example. 回答1: Do push to promises only synchronously, so that you know when you are finished. Since your