q

Node; Q Promise delay

笑着哭i 提交于 2019-12-17 14:56:50
问题 Here are some simple questions based on behaviour I noticed in the following example running in node: Q('THING 1').then(console.log.bind(console)); console.log('THING 2'); The output for this is: > "THING 2" > "THING 1" Questions: 1) Why is Q implemented to wait before running the callback on a value that is immediately known? Why isn't Q smart enough to allow the first line to synchronously issue its output before the 2nd line runs? 2) What is the time lapse between "THING 2" and "THING 1"

Is there a way to return early in deferred promise?

谁说胖子不能爱 提交于 2019-12-17 06:54:21
问题 So I have a promise which contains multiple checks like this function test(){ var deferred = q.defer() var passed = false if(!passed){ deferred.reject("Don't proceed") //return } else { if(!passed){ deferred.reject("Don't proceed") } else { if(!passed){ deferred.reject("Don't proceed") } else { setTimeout(function(){ console.log("Hello"); deferred.resolve() }, 100); } } } return deferred.promise } This looks bad because there is a pyramid at the bottom. I'm wondering is there something like

javascript promise not passing all arguments (using Q)

天大地大妈咪最大 提交于 2019-12-17 06:51:57
问题 I am having trouble passing all arguments. My promise callback only receives one instead of three: var asyncFunction= function(resolve) { setTimeout(function() { resolve("Some string that is passed", "and another", "third"); }, 1000); }; var promiseFunction = function () { var deferred = Q.defer(); asyncFunction(deferred.resolve); return deferred.promise; }; promiseFunction().then(function() { // Only one argument is passed here instead of 3 // { '0': 'Some string that is passed' } console

Recursion using promise api

岁酱吖の 提交于 2019-12-13 20:53:25
问题 Please find the code here http://plnkr.co/edit/zwCYGQaxyGyr7kL6fLKh?p=preview I am trying to do recursion with an async function which uses promise. I wanted to happen it serially (so no $q.all), and want to wait till all the nodes are processed before the then of the main call to be fired. In other words, You are exited needs to be printed at the end. How can I do that? thanks. program var asyncPrint = function(val) { var deferred = $q.defer(); $timeout(function() { deferred.resolve(console

Sequential Message Sending Using Facebook Send-API

大城市里の小女人 提交于 2019-12-13 20:43:33
问题 I'm trying to send messages using FB Send-Message API in sequential order, but have an issue with it. As a result my bot sends messages in wrong order. I have the following functions: function sendMessage(recipient, payload, accessToken) { return axios.post(baseURL + 'v2.11/me/messages/?access_token=' + accessToken, Object.assign({}, { messaging_type: "RESPONSE", recipient: { id: recipient } }, payload) ); } (1)(returns Promise of sending message); let async_actions; let promise_chain = Q

Using Kris Kowal's Q. How should I catch if any errors have been thrown throughout the life of a chained promise?

梦想的初衷 提交于 2019-12-13 14:19:05
问题 I'm new to promises, and I just started using Kris Kowal's Q today (I've read about it before and used it a little with Angular.js), and I was doing an Ajax call with jQuery and turning it into a Q promise. I was trying to find a good way to have some sort of catch at the end that would tell me whether this promise was rejected at one point or not so I could tell the user something went wrong along the way. The idea is I want to extend the idea to work no matter how long my promise and at the

Is changing the meaning of promise methods a good idea? [closed]

回眸只為那壹抹淺笑 提交于 2019-12-13 10:34:05
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 5 years ago . I have a long running method in Node.js that keeps listening for command line output until the user closes the command or an error halts. Long story short, this method had, among others, three callbacks: on_receive : Returns any new output from the command line to the

Call to modules in specific order in node

*爱你&永不变心* 提交于 2019-12-13 08:32:00
问题 I've used the following code to call two modules, but the invoke action is called before the validate file (I saw in debug). What I should do to verify that validateFile is called before appHandler.invokeAction ? Should I use a promise? var validator = require('../uti/valid').validateFile(); var appHandler = require('../contr/Handler'); appHandler.invokeAction(req, res); Update this is the validate file code var called = false; var glob = require('glob'), fs = require('fs'); module.exports =

how to make synchronous http calls using promises in node.js

安稳与你 提交于 2019-12-13 08:19:12
问题 I would like to iterate thru an array of students and make http call for each of them and parse the response and insert into mongodb, so I would like to do this for each student one by one untill all data are inserted then continue with the next one so that it would be better for the CPU and RAM Memory... So far I am doing this, but this for some reason is not what I wanted... var startDate = new Date("February 20, 2016 00:00:00"); //Start from February var from = new Date(startDate).getTime(

How can I properly call a list of async functions in order? [duplicate]

走远了吗. 提交于 2019-12-13 07:43:08
问题 This question already has an answer here : How to sequentially run promises with Q in Javascript? (1 answer) Closed 4 years ago . I am attempting to write a "robocopy /mir" like function within Node.js and cannot seem to wrap my head around how to properly execute several async functions in order. Some background: The script is run on Windows, therefore, I needed to find some way to copy files while retaining modification time AND receiving progress notifications. To solve this problem, I