deferred

Angular/Jasmine testing with deffered promises

时光总嘲笑我的痴心妄想 提交于 2019-12-22 08:03:53
问题 I am testing a controller using a combination of angular and jasmine, and am not completely sure about using deffered promises. This is my spec code. describe('Controller Tests', function(){ var scope, searchAPI; beforeEach(function(){ var mockSearchAPI = {}; module('myApp', function($provide){ $provide.value('searchAPI', mockSearchAPI); }); }); inject(function($q){ var testData = {"message":"hi"}; mockSearchAPI.executeSearch = function(){ var defer = $q.defer(); defer.resolve(testData);

Reuse jQuery.post() / jQuery.Deferred() object

蓝咒 提交于 2019-12-22 04:43:35
问题 the simplest example of what I'm looking for is this: var messageLoader = $.post("api/user/messages", {api:data}) messageLoader.done(function(data){ //do something }); This works brilliantly, but only once. If I want to update the data, I have to redefine everything. I can't seem to find any call for the Deferred Object that let's me restart it. i.e. messageLoader.redo() , which ideally would re-do the POST request, and subsequently call the same "done" handler without me having to re-define

Google App Engine timeout: The datastore operation timed out, or the data was temporarily unavailable

我怕爱的太早我们不能终老 提交于 2019-12-20 20:36:54
问题 This is a common exception I'm getting on my application's log daily, usually 5/6 times a day with a traffic of 1K visits/day: db error trying to store stats Traceback (most recent call last): File "/base/data/home/apps/stackprinter/1b.347728306076327132/app/utility/worker.py", line 36, in deferred_store_print_statistics dbcounter.increment() File "/base/data/home/apps/stackprinter/1b.347728306076327132/app/db/counter.py", line 28, in increment db.run_in_transaction(txn) File "/base/python

Implement Deferred object without using jquery

两盒软妹~` 提交于 2019-12-20 10:47:54
问题 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 =

The deferred call's arguments are evaluated immediately

一世执手 提交于 2019-12-20 01:06:04
问题 In A Tour of Go is written: The deferred call's arguments are evaluated immediately, but the function call is not executed until the surrounding function returns. I have difficulty in understanding the first part of the quote. What is called immediately? func def(s string) func() { fmt.Println("tier up") fmt.Println(s) return func(){ fmt.Println("clean up") } } func main() { defer def("defered line")() fmt.Println("main") } //Output: //tier up //defered line //main //clean up https://play

Wait for the end of an asynchronous Javascript function to retrieve a result (Deferred ?)

浪尽此生 提交于 2019-12-19 04:14:46
问题 Ok guys, I know this topic has already been discussed multiple times, but I can't find an answer to solve my problem. So I'm trying to do a simple think : I'm creating a string, like : distance is : " + CalculateDistance(position); The wanted result is something like distance is 5kms (8min) . CalculateDistance(position) is a function calling a Google maps API called DistanceMatrix to calculate distance between two points. The API is documented here, and the given sample perfectly works. I

Sequential function calls in javascript

ぃ、小莉子 提交于 2019-12-19 04:10:09
问题 I want function A to finish execution and only after that function B should start executing. When I call function A and then function B, it seems both are executing simultaneously. And after function B completes, I want to call a third function update_dropdown(). My code looks like this: function A { for (var i = 0; i < 5; i++) { var promise = $.get(url+i); $.when(promise).then(function () { $.post(url); }); } } function B { var x = $.get(url); var promise = $.post(url+x); $.when(promise0)

jQuery deferred: cancel progress

半城伤御伤魂 提交于 2019-12-18 20:08:06
问题 Is there a way to cancel a deferred callback queue in progress? I have an arbitrary amount of ajax calls. I'd like to stop further ajax requests when data of success returns specific marker: this.oDeferred=$.Deferred(); this.oChain=this.oDeferred; for(var i=0; i<this.aKey.length; i++) { (function(iKey,self) { self.oChain=self.oChain.then(function(){ return $.ajax({ url:self.aUrl[iKey], type:'post', data:{'ajax':true}, dataType:'json', success:function(data) { if(data.bCancel==true) { //stop

Deferrable check constraint in PostgreSQL

╄→尐↘猪︶ㄣ 提交于 2019-12-18 19:02:45
问题 I have function checking mandatory participation as follows: CREATE FUNCTION member_in_has_address() RETURNS BOOLEAN AS $$ BEGIN RETURN EXISTS (SELECT * FROM address a, member_details b WHERE b.member_id = a.member_id); END; $$ LANGUAGE plpgsql; Then called from CHECK constraint ALTER TABLE member_details ADD CONSTRAINT member_in_has_address_check CHECK (member_in_has_address()); To create deferable constraint in Standard SQL it would be: ALTER TABLE member_details ADD CONSTRAINT member_in

How do I debug my asynchronous, promise based code if the library is swallowing all the exceptions?

被刻印的时光 ゝ 提交于 2019-12-18 12:16:54
问题 The Problem JSFiddle : http://jsfiddle.net/missingno/Gz8Pe/2/ I have some code that looks like this: var d = new Deferred(); d.resolve(17); return d.then(function(){ //do some stuff... }) .then(function(){ var obj = a_funtion_that_returns_null_on_IE(); var x = obj.some_property; //BOOM! }); The problem is that when I am on IE all I can see are 'obj' is null or not an object errors, without any reference to the corresponding line number and without the debugger halting at the offending line