q

How to use $q to get a promise from a $broastcast in angularJS

旧城冷巷雨未停 提交于 2019-12-13 07:07:35
问题 Right now my controller code looks like this: $scope.spAPI.load(id).then(function(result){ var deferred = $q.defer(); if(result !== undefined){ deferred.resolve($rootScope.$broadcast("onSpLoaded", result)); } return deferred.promise; }).then(function(success){ $scope.modalInstance = $modal.open({ ... }); }); I want the modal instance to be opened AFTER the broadcasts are processed. Is there a way to do this? Update: I was thinking about this problem backwards. I meant to do the broadcast

Should I return the result of deferred.resolve/reject?

我是研究僧i 提交于 2019-12-13 06:02:13
问题 When working with Q deferreds, should I return the result of deferred.resolve and deferred.reject ? function foo() { var deferred = Q.defer(); service.doSomethingAsync({ success: function() { deferred.resolve(); // should I return the result of resolve here? }, fail: function(err) { deferred.reject(err); // should I return the result of reject here? } }); return deferred.promise; } 回答1: Your code can be changed to: function foo() { var deferred = Q.defer(); service.doSomethingAsync({ success:

Q.all doesn't call tasks

流过昼夜 提交于 2019-12-13 04:44:00
问题 So I have this CoffeeScript (simplified to focus on the real problem) Q = require 'q' events = require 'events' class SomeObj extends events.EventEmitter constructor: () -> setTimeout () => @emit 'done' , 3000 class SomeObj2 extends events.EventEmitter constructor: () -> setTimeout () => @emit 'done' , 50000 class Main someObj1: null someObj2: null constructor: () -> Q.all([ => @task1(), => @task2()]) .then (results)-> console.log 'results' console.log results .catch((error)-> console.log

I need some help promises and q library

前提是你 提交于 2019-12-13 04:41:01
问题 I need some help on syntax with node.js promises . In readme for node.js module called q https://github.com/kriskowal/q is written something I don't understand. Why do they always write return before promise ? return Q.fcall(eventualAdd, 2, 2); How do I make an asynchronous function with callback into function that returns promise ? I try function doThis(a,b, callback) { var result = a+ b; setTimeout( callback, 2000, result);} Q.ncall(doThis, 2,3).then( function(result) { alert(result); }); I

Create an api which accepts a callback, and also returns a promise

余生颓废 提交于 2019-12-12 21:33:31
问题 So I'm trying to upgrade an existing api to support promises, but I want to maintain backwards compatibility. So, let's say this is my api: module.exports = { deliverPost: function(callback) { someAsyncFunction(function(err) { if (err) console.log(err); callback(err); }); } } That's great, I can call it and pass a callback, and everything works. Now we do the same thing with promises: var q = require('q'); module.exports = { deliverPost: function() { return q.nfcall(someAsyncFunction).catch

mongoose and q promises

谁都会走 提交于 2019-12-12 10:47:47
问题 I'm working from the mongoose/q promises framework sample here, but seem to have some issues with the nfbind when trying to use findOne, mainly since the samples from the Q framework don't seem to match those in the gist. My code: var mongoose = require('mongoose'); var Q = require('q'); var user_schema = mongoose.Schema({username:String, last_touched:Date, app_ids:[String]}); var user = mongoose.model('user', user_schema); exports.user = user; exports.user.find = Q.nfbind(user.find); exports

Cordova android build error

左心房为你撑大大i 提交于 2019-12-12 09:46:16
问题 I get this error, when i try to build and run an cordova project on an android device: Running app on platform "android" via command "***/Documents/***/App/platforms/android/cordova/run" --device [Error: An error occurred while running the android project. /***/Documents/***App/platforms/android/cordova/node_modules/q/q.js:126 throw e; ^ Error executing "ant clean -f /***/Documents/***/App/platforms/android/build.xml": Build failed Any suggestion on fixing this problem? 回答1: Check if "adb

Using promises - Logging stack trace in fail handler

我与影子孤独终老i 提交于 2019-12-12 08:17:26
问题 I am rather new to nodejs so I will explain in a bit more detail what I am trying to do. I have a webserver. If a request fails I want to log the stack trace of that exception, but deliver a error page and not crash the server. As an example, the function handling the requests: var Q = require('q'); var requestHandler = function () { // Here I get the data etc. that was requested. As this is not important, just a dummy here Q.resolve() // Now I answer the request .then(function (data) { //

How to abort a failing Q promise in Node.JS

天涯浪子 提交于 2019-12-12 04:14:41
问题 Let's say I'm building a registration flow, and I have something that looks like this: Q.nfcall(validateNewRegCallback, email, password) .fail(function(err){ console.log("bad email/pass: " + err); return null; }) .then(function(){ console.log("Validated!"); }) .done(); If my registration fails, I'd like to catch it, and die. Instead, I see both "bad email/pass" and "validated". Why is that, and how can I abort in the first failure call? 回答1: The fail handler does catch rejected promises, but

Equivalent behaviour of 'jQuery.active' in q

╄→尐↘猪︶ㄣ 提交于 2019-12-12 03:55:33
问题 In my c# selenium webdriver tests I occasionally have to make use of: public void WaitForJQuery(TimeSpan timeout) { var wait = new WebDriverWait(driver, timeout); wait.Until(d => (bool)(d as IJavaScriptExecutor).ExecuteScript("return jQuery.active == 0")); } This waits up until the specified 'timeout' for jQuery calls to finish. I was wondering if there was an equivalent I could use for the q.js library? I'm a tester not a webdesigner and have very little experience with the q library,