q

Queuing promises

喜你入骨 提交于 2019-11-30 09:51:32
I use mbostock/queue for queuing few async operation. It is more to rate limit (UI generate few events, where the backend can process it slowly), and also to make sure they are processed sequentially. I use it like function request(d, cb) { //some async oper add.then(function(){ cb(null, "finished ") }) } var addQ = queue(1); addQ.defer(request) //called by few req at higher rates generated by UI I already uses angular.js $q for async operation. So, do I have to use mbostock/queue , or can I build a queue out of $q (which is in spirit https://github.com/kriskowal/q ) Thanks. Basic $q Chain

How to use “q” module for refactoring mongoose code?

孤人 提交于 2019-11-30 08:30:35
I'm using mongoose to insert some data into mongodb. The code looks like: var mongoose = require('mongoose'); mongoose.connect('mongo://localhost/test'); var conn = mongoose.connection; // insert users conn.collection('users').insert([{/*user1*/},{/*user2*/}], function(err, docs) { var user1 = docs[0], user2 = docs[1]; // insert channels conn.collection('channels').insert([{userId:user1._id},{userId:user2._id}], function(err, docs) { var channel1 = docs[0], channel2 = docs[1]; // insert articles conn.collection('articles').insert([{userId:user1._id,channelId:channel1._id},{}], function(err,

Is there a pure Promise-based approach for mapping/concatenating collections?

流过昼夜 提交于 2019-11-30 07:54:54
问题 async vs. Q generally I'm learning Node.js development, and trying to wrap my brain around strategies for managing asynchronous "callback hell". The two main strategies I've explored are Caolan McMahon's async module, and Kris Kowal's promise-based Q module. Like many other people, I'm still struggling to understand when you should use one vs. the other. However, generally speaking I have found promises and Q-based code to be slightly more intuitive, so I have been moving in that direction.

Promises and generic .catch() statements

蹲街弑〆低调 提交于 2019-11-30 02:46:15
问题 I'm writing an API for my system, that's sending an XHR to the server and returns a promise that should be handled by the caller - so far so good. For each API call I must use a .then and .catch calls, but usually (like 75% of the time) the .catch references the same functionality which simply prints using console.error . My question is - Is there a way to attach a default catch statement for each promise that I create? (that let's say prints to the console), and for each promise that I would

How can I promise-ify a one-off usage of gulp in my application?

前提是你 提交于 2019-11-30 01:43:54
问题 As part of a small program I'm writing, I would like to use gulp to convert a large set of a files to markdown. This is not part of a build step separate from the program. It's a part of the program. So I'm not using a gulpfile to handle this. The problem is, since it's async, I want to use a promise which will alert me when the gulp task is finished. Something like this would be ideal: io.convertSrc = function() { var def = q.defer(); gulp.src(src + '/*.md') .pipe(marked({})) .pipe(gulp.dest

How to configure additional classpath in SpringBoot?

让人想犯罪 __ 提交于 2019-11-30 01:05:53
问题 I want to make a standalone web application. I have some problems with SpringBoot. My application is one jar file from SpringBoot. But my application was usually needed jdbc driver jar. I want to exclude the jdbc driver jar for my application and read the library jar from the lib folder. But SpringBoot lib folder is BOOT-INF/lib is final static . So, I want to add external classpath (lib) for the jdbc driver jar. How to configure additional classpath in SpringBoot. Is it available? 回答1: You

How to call Q promise notify within the promise chain

那年仲夏 提交于 2019-11-29 14:31:40
I need helps on notify() within the promise chain. I have 3 promise base functions connect() , send(cmd) , disconnect() . Now I would like to write another function to wrap those call in following manner with progress notification. function bombard() { return connect() .then(function () { var cmds = [/*many commands in string*/]; var promises = _.map(cmds, function (cmd) { var deferred = Q.defer(); deferred.notify(cmd); send(cmd).then(function (result) { deferred.resovle(result); }); return deferred.promise; }); return Q.all(promises); }) .finally(function () { return disconnect() }) } Run the

Chaining waterline calls with Promises

不打扰是莪最后的温柔 提交于 2019-11-29 12:11:38
问题 I have been hitting my head off a wall on this for the last 3 days. I am using sailsjs & the waterline ORM that comes bundled. I want to run DB calls one after an other. I know I can do this by nesting inside "then" calls but it just looks wrong. I have gone over the Q documentation and tutorials several times but I still don't get how to connect and fire "then" calls from existing Promises sequentially :( I want to: create a user create a action link the user & action update the user update

Unhandled rejection reasons (should be empty)

核能气质少年 提交于 2019-11-29 09:19:53
I'm getting into promises pattern with Q and I keep getting warning "[Q] Unhandled rejection reasons (should be empty)" in console. What em I doing wrong? http://jsfiddle.net/FpyDr/1/ function load(url) { var deferred = Q.defer(); $.ajax({ type: "GET", processData: false, dataType: "html", url: url, cache: false }).done(function (response, status, xhr) { deferred.reject(new Error("test error")); return; }).fail(function (xhr, status, error) { deferred.reject(new Error("ajax failed")); return; }); return deferred.promise; } load("http://fiddle.jshell.net") .then(function (result) { console.log(

Is there a pure Promise-based approach for mapping/concatenating collections?

二次信任 提交于 2019-11-29 05:38:53
async vs. Q generally I'm learning Node.js development, and trying to wrap my brain around strategies for managing asynchronous "callback hell". The two main strategies I've explored are Caolan McMahon's async module, and Kris Kowal's promise-based Q module. Like many other people , I'm still struggling to understand when you should use one vs. the other. However, generally speaking I have found promises and Q-based code to be slightly more intuitive, so I have been moving in that direction. Mapping/Concatenating collections generally However, I'm still stuck using the async module's functions