deferred

Node.js deferred promisify + mongoose

别说谁变了你拦得住时间么 提交于 2019-11-29 18:04:37
Has anyone worked with the nodejs modules 'deferred' and 'mongoose'? I'm trying to get the deferred.promisify method to work on mongoose models' functions so I can chain them easily, but running into some troubles. Specifically, I'd like to promisify the find and findById functions so I can chain finding one document referenced by another document by ObjectID. Here's what I've got: https://gist.github.com/3321827 However, this seems less than ideal since the getAppPermissions and getApplication functions seem to be little more than wrappers for the find and findById methods of the mongoose

Re-using deferred objects in Twisted

前提是你 提交于 2019-11-29 16:26:07
In Twisted, it seems that a deferred object can only be used once after its callback has fired, as opposed to other "promise"-based libraries I've worked with: from twisted.internet import defer class Foo(object): def __init__(self): self.dfd = defer.Deferred() def async(self): return self.dfd @defer.inlineCallbacks def func(self): print 'Started!' result = yield self.async() print 'Stopped with result: {0}'.format(result) if __name__ == '__main__': foo = Foo() foo.func() import time time.sleep(3) foo.dfd.callback('3 seconds passed!') foo.func() On standard out, one has: $ Started! $ Stopped

Defer attribute doesn't work with Google Maps API?

南楼画角 提交于 2019-11-29 07:19:56
I'm trying to make sure the Google map is the last thing that loads on the page and doesn't affect the performance of the page negatively. When the defer attribute is placed after ...sensor=false", the map does not appear. What's the best way to use the defer attribute with Google maps? Is this even possible? <div id="map-canvas"></div> <script src="http://maps.googleapis.com/maps/api/js?key=AIzaSyDY0kkJiTPVd2U7aTOAwhc9ySH6oHxOIYM&sensor=false" defer></script> <script defer> function initialize() { var mapOptions = { center: new google.maps.LatLng(37.7599446, -122.4212681), zoom: 12,

jquery when/then (also when/done) not waiting

随声附和 提交于 2019-11-29 06:43:49
问题 I've looked at many samples that use this syntax, but I can't see what I"m doing wrong. The "then" function is running before the ajax call returns. I've tried also using $.deferred and a few other patterns to no avail. Can someone see what I'm missing? I have debugged and can see the calls being made from inside the done/then before the ajax call returns it's success (or error) data. Thanks for any help. Main call: this.addFirstTask = function(task) { var totalHours = GetHours(); $.when

AngularJS - why promises ($q) with $http?

让人想犯罪 __ 提交于 2019-11-28 20:37:03
问题 I am learning AngularJS after converting from jQuery for a few years. And some bits are much more intuitive. Some not so much :). I am trying to get my head around the use of promises, particularly $q in use with $http and there does not seem to be too much information around these two combined that I can find. Why would I use promises in place of the success/error callback? They both make uses of callbacks in reality, so why is a promise considered better? E.g. I could set up a get(...)

jquery deferred in .each loop

落花浮王杯 提交于 2019-11-28 19:13:24
This should be a simple one. I have a function that is called and I need to wait for all the async operations to complete. what I want is something like this... self.processSchema(data).done(function(results){ //do stuff}); The processSchema function loops using $.each and calls an async method. var processSchema = function(data) { var def = new $.Deferred(); $.each(table, function() { //calls an async SQLitePlugin method db.executeSql(sql, data, function(tx, results){ def.resolve(results); } } return(def.promise()); } This does not seem to work, I am new to $.Deferred so any guidance would be

How to always run some code when a promise is fulfilled in Angular.js

*爱你&永不变心* 提交于 2019-11-28 19:02:55
In my Angular.js application, I'm running some asynchronous operation. Before it starts I cover the application with a modal div, then once the operation is complete, I need to remove the div, whether the operation was successful or not. Currently I have this: LoadingOverlay.start(); Auth.initialize().then(function() { LoadingOverlay.stop(); }, function() { LoadingOverlay.stop(); // Code needs to be duplicated here }) It works well, however I would prefer to have something cleaner like this pseudo-code: LoadingOverlay.start(); Auth.initialize().finally(function() { // *pseudo-code* - some

Node.js deferred promisify + mongoose

旧时模样 提交于 2019-11-28 12:05:01
问题 Has anyone worked with the nodejs modules 'deferred' and 'mongoose'? I'm trying to get the deferred.promisify method to work on mongoose models' functions so I can chain them easily, but running into some troubles. Specifically, I'd like to promisify the find and findById functions so I can chain finding one document referenced by another document by ObjectID. Here's what I've got: https://gist.github.com/3321827 However, this seems less than ideal since the getAppPermissions and

Re-using deferred objects in Twisted

隐身守侯 提交于 2019-11-28 11:54:19
问题 In Twisted, it seems that a deferred object can only be used once after its callback has fired, as opposed to other "promise"-based libraries I've worked with: from twisted.internet import defer class Foo(object): def __init__(self): self.dfd = defer.Deferred() def async(self): return self.dfd @defer.inlineCallbacks def func(self): print 'Started!' result = yield self.async() print 'Stopped with result: {0}'.format(result) if __name__ == '__main__': foo = Foo() foo.func() import time time

AngularJS promises not firing when returned from a service [duplicate]

半腔热情 提交于 2019-11-28 07:03:07
Possible Duplicate: angularjs - promise never resolved in controller I'm wrapping a slow WebSockets server in a AngularJS service, and then calling into that service from my controllers. If I chain callbacks onto callbacks onto callbacks, everything works just fine, any the UI updates asynchronously. When I try to use $q.defer() to clean up that mess of callbacks, it seems my deferred never gets called. I'm familiar with the concepts of deferred from Python's Twisted, so I think conceptually everything should work - but it doesn't. This is the shortest example I could come up with, the slow