Questions tagged [q]

The Q.js JavaScript promise library. Q catches errors and uses a `then` technique to handle JavaScript callbacks and exceptions. Do *not* use for Angular's $q, use [angular-promise] instead! Also do *not* use for kx System's kdb+/q, use [kdb] or [q-lang] instead! Lastly, this tag should not be used for questions regarding Android 10 - use the [android-10.0] tag instead!

A JavaScript library for the browser and Node.js for making and composing asynchronous promises. Q catches errors and uses a then technique to handle JavaScript callbacks and exceptions.

1381 questions
0
votes
1 answer

Q and mongoose confusion

I'm doing some slightly complex post processing on some mongoose documents and I ended up adding Q to help with managing the async. I can get things working but I'm a little confused by what's going on under the hood and why I get different behavior…
0
votes
4 answers

How can I chain together groups of promises?

I am using the Q javascript promises library and am running in a browser, and I want to figure out how to chain together groups of promises so that each group gets executed sequentially. For example, if I have items A, B, C, and D, I want to group…
Chris Farmer
  • 24,974
  • 34
  • 121
  • 164
0
votes
1 answer

Node.JS + Zlib + Q (promises) - How do I change compression performance in a sugar way?

I am a big fan of sugar. Here's how a gzip compression statement works in Node.JS: var q = require('qtree'); var zlib = require('zlib'); q(someData) .then(q.nbind(zlib.gzip, zlib)) .then(function(gzippedData) { // play with gzipped…
Redsandro
  • 11,060
  • 13
  • 76
  • 106
0
votes
1 answer

Node.js and asynchronous programming with Q

Is the following the correct way to go about things? This is a sign up controller action. Im creating a user and a group to add the user to. Notice I have method level variables called user and group. The rest of the code is asynchronous using the Q…
user3428172
  • 147
  • 2
  • 6
0
votes
1 answer

Clean way of keeping an aggregate of a sequence of Q.all promises

I would like to maintain an aggregate of intermediate results when executing a series of Q.all tasks. Concretely the problem is as follows: var Obj = function(first, second) { return { stuff: first, otherStuff: [1,2], …
JoelKuiper
  • 4,362
  • 2
  • 22
  • 33
0
votes
1 answer

Q async library with node.js

Im working on nodejs using Q as my async module. The following invokes the first function, but nothing after that and the app doesnt return anything - it just keeps waiting. return Q.ninvoke(exports, 'parseUser', req, null) .then(function(user)…
user3428172
  • 147
  • 2
  • 6
0
votes
1 answer

AngularJS: run asynchronous events sequentially with $q / defer

I want to use $q to run events but I do (for reasons not relevant to the question) care what order they occur in. How can I use promise.then() to run things sequentially without ending up with heavily nested functions? Simplified example var…
Ade
  • 2,961
  • 4
  • 30
  • 47
0
votes
1 answer

Q/Promise handle callback params

var Q = require("q"); function test(v){ var deferred = Q.defer() if (v) { console.log("success"); deferred.resolve(); } else{ console.log("failed"); deferred.reject(new Error("failed")) } return…
xieyu33333
  • 55
  • 5
0
votes
2 answers

Simple new + then for Q promises

I'm trying to use Q Promise implementation, but am facing strange inconsistency. When I run in Chrome m33, the following code: new Promise(function(resolve, reject) { resolve(1); }).then(function(value) { console.log(value); }); It works…
kirilloid
  • 14,011
  • 6
  • 38
  • 52
0
votes
2 answers

Creating promises

I am having trouble with creating / understanding promises. I understand the advantages and understand how to use them. Creating own promise-functionality is the difficult part. Simply, how do I convert this function to work with…
Hachi
  • 536
  • 6
  • 17
0
votes
0 answers

Q, amd and concatenation with grunt

I'm using AMD-like function in my project, but all js files are concatenated into one (with grunt-contrib-concat). I want Q to be concatenated as well. The problem is I can't declare Q as dependency in my other modules, cause it declares itself as…
kirilloid
  • 14,011
  • 6
  • 38
  • 52
0
votes
2 answers

Q does not resolve after For loop making asynchronous calls

Pretty straightforward here, but it seems I'm missing some nuance. I'm creating an array of promises, and using Q.all() to ensure that all inserts into a db are finished before shipping a response back to the client. However, it's never being…
freedomflyer
  • 2,431
  • 3
  • 26
  • 38
0
votes
1 answer

Collecting Q Promise in function before returning

I have a function that is using promises and the Q library, essentially I want to wait until all the promises have compelted before returning, but my code is just falling through: function makeSomething(){ var something = new Something() …
akaphenom
  • 6,728
  • 10
  • 59
  • 109
0
votes
1 answer

How to use q.js to chain backbone model?

I have the following: var q = new app.models.OverwriteLineItemsProcess(); q.set('id', $("#process_id").val()); q.saveSource($("#source_quote").val()); q.lockSource(); saveSource is sending data to the backend using ajax. So is lockSource. I want to…
Kim Stacks
  • 10,202
  • 35
  • 151
  • 282
0
votes
2 answers

How to synchronize MongoDB async query in NodeJS

I have a for-loop statement and an async MongoDB inside loop body. What I want to do is to make a find query from my MongoDB database, and push the result into an Array. Here is the code: function() arrResult() { var arr = []; for(...) { …
Afshin Mehrabani
  • 33,262
  • 29
  • 136
  • 201