q

NodeJS My SQL query with Chain promise

↘锁芯ラ 提交于 2019-12-22 17:54:10
问题 I have 3 function and i want to call this function to step by step, for example when i will call firs function and get result, i have to call second function and pass parameter returned from first call. after i will finish second call i have to call third function and pass parameter returned from second function. #1: getCategory = function (branch_id) { var deferred = q.defer(); var categoryData; var query = 'SELECT id,name,price,currency FROM category where branch_id=?'; pool.getConnection

Concurrency limit in Q promises - node

混江龙づ霸主 提交于 2019-12-22 05:03:25
问题 Is there any method to limit concurrency of promises using Q promises library? This question is kinda related to How can I limit Q promise concurrency? but the problem is that I'm trying to do something like this: for (var i = 0; i <= 1000; i++) { return Q.all([ task1(i), task2(i) ]); // <-- limit this to 2 at a time. } The real use case is: Fetch posts from DB Loop every post in DB like posts.forEach(function(post) {} For every post do task1, task2, task3 (retrieve social counters, retrieve

Promise how to implement in this situation?

邮差的信 提交于 2019-12-22 00:53:54
问题 i have a problem with sync using fs.readfile, they are not inicializing at the first time, if i try request again, then i have results. I know i can use promise and i find something useful with Q from Kriskowal. I tried it but without success. I didn´t understand very well how to implement it. If someone can help with this, i will be eternally grateful. code: "use strict" var Q = require('q'); var fs = require('fs'); var arrayZipBand = []; var jsonZipCode = []; var arrayParsedZipcodeBr = [];

Resolving breeze query/Q promise with $route resolve stops page

烂漫一生 提交于 2019-12-21 21:26:48
问题 I'm having problems executing a breeze query with angular resolve before the view is rendered. I'm trying to get some data from the server before the view is rendered with breeze. I'm using $routeProvider.when('/countries', { templateUrl: 'App/partials/countries.html', controller: Ctrl, resolve: Ctrl.resolve }). controller and service snippets: function Ctrl($scope, Q, datacontext, countries) { //... } function getCountries(forceRefresh) { var query = entityQuery. from("countries"). orderBy(

chaining promises with q.js

扶醉桌前 提交于 2019-12-21 07:26:18
问题 I'm trying to understand how promise chaining works. I'm using q.js. Here's what I'm playing with. var Q = require("q"); // npm install q // the function Q(value) returns a fulfilled promise with the value... I think. Q(1).then(Q(2)).then(Q(3)).then(Q(4)).then(function(n) { console.log(n); }); Q(1).then(function(n) { return Q(2); }).then(function(n) { return Q(3); }).then(function(n) { return Q(4); }).then(function(n) { console.log("done: " + n); }); My question basically boils down to why

How to wait for a promise to be resolved?

非 Y 不嫁゛ 提交于 2019-12-21 03:08:30
问题 I'm dealing with a NodeJs framework that requires a certain function to be synchronous, but I need to retrieve a value that can only be accessed asynchronously. In a perfect world, I would be able to return a promise, but I can't. As a quick-and-dirty solution, I created the following method: exports.synchronizePromise = function(promise) { var value; promise.then(function(promiseValue) { value = promiseValue; }); while (!value) {} // Wait for promise to resolve console.log("DONE: " + value);

How to use Q.all() with complex array of promises?

ぃ、小莉子 提交于 2019-12-20 20:19:22
问题 Consider I have an array of objects and promises, something like: [{ a: 1 }, { a: 4 }, { a: 4 }, { promiseSend: [Function], valueOf: [Function] }, { promiseSend: [Function], valueOf: [Function] }] Now when call I Q.all(arr) and return the object value in then() , nothing's happen and still my array contains promise objects. Is there any way to work with the Q.all() and such a complex arrays? 回答1: That's how Q is supposed to work. To get all the values, not the promises, you may use .spread()

angularjs simple .then or $q service in async requests

送分小仙女□ 提交于 2019-12-20 04:24:28
问题 I don't know what is the exactly difference between AngularJS $q service and simply using .then() after async request. Simple example with .then() : function InboxService($http) { this.getEmails = function getEmails() { return $http.get('/emails'); }; } And when using the service (just part of code): InboxService.getEmails() .then(function (response) { // use response }); What is the difference with $q service with resolve and reject ? 回答1: What is the difference with $q service with resolve

Difference between “Q” and “q” in angularjs and requirejs

六眼飞鱼酱① 提交于 2019-12-20 03:12:07
问题 I am creating a single page app built on AngularJS, Breeze, and RequireJS. In setting up AMD with requirejs to work with Angular and Breeze, I encountered an issue with Breeze's dependency on "q". If the configuration rule for "q" is lowercase, even if there is no explicit export in the "shim", Breeze gives this error: Uncaught Error: Unable to initialize Q. See https://github.com/kriskowal/q "http://localhost:1498/Scripts/shared/breeze.js"breeze.js:1` When require config changes all

$q.all and nested promises

喜你入骨 提交于 2019-12-19 18:49:13
问题 Have a question about synchronizing nested promises when using $q in Angular. Will the following code ensure that the entire chain of promises is waited for? Meaning will the nested calls to services that return promises be waited for in the $q.all block? var call1 = service1.get('/someUr').then(function(){ return service2.get('/someUrl2'); //returns promise }); var call2 = service3.get('/someUr').then(function(){ return 'hello'; }); var call3 = service4.get('/someUr').then(function(){ return