async.js

Node Async - Callback was already called - using 2 for loops and an if statement

南楼画角 提交于 2020-01-06 07:27:18
问题 Could someone please explain why I keep seeing the Error: Callback was already called . I feel I have covered all cases - so why would be 'already called': function addVertices(outercallback) { async.forEachLimit(fullData, 25, function (data, innercallback) { myJson.matches.forEach(function (oMatches) { if (data.$.id == oMatches.SourceId) { oMatches.Ids.forEach(function (oId) { client.execute("g.addV('test').property('id', \"" + oId + "\")", {}, (err, results) => { if (err) { return

how to show async data in UI

╄→гoц情女王★ 提交于 2020-01-06 05:30:08
问题 I wrote an async function that needs to call a program in the server and that program generate a file which needs to load in UI for displaying. I am not sure how to show the result in my UI since execFile is async function and it may take few second results to be ready? Do I need to have kind of infinity loop to check the result is ready in the server? I am using nodejs-express handlebars. router.post('/',function(req, res, next) { const child = execFile('program.exe', ['in.sql'], (error,

Node.js - Async - multiple innercallbacks within a if statement

孤街浪徒 提交于 2020-01-06 04:34:12
问题 I'm using Node.js and the async library, however I keep seeing the error: Callback was already called . I think I understand why I get the error, however I don't know if it is actually possible to do the following/how can resolve. Basically I want both the innercallbacks to have completed before the outercallback is completed. So the code with which I am facing this issue looks like: async.forEachLimit(inData, 25, function (data, innercallback) { myJson.matches.forEach(function (oMatches) {

How to gather the result of Web APIs on nodeJS with 'request' and 'async'

这一生的挚爱 提交于 2020-01-04 05:22:14
问题 I'm writing a test code which gathers the result from Web APIs on node.js by using 'request.js' and 'async.js'. Here's my sample code; var request = require('request'); var async = require('async'); var addresses = [ "Tokyo", "Moscow", "Bagdhad", "Mountain View", "New York", ]; function accessUrl( address, callback ) { options ={ headers: {'user-agent': 'Mozilla/5.0'}, url: 'http://api.openweathermap.org/data/2.5/weather?q=' + address, json: true }; request.get(options, function(err, response

How to stop executing waterfall on error in async of node.js?

僤鯓⒐⒋嵵緔 提交于 2020-01-02 13:42:06
问题 I am using async module with waterfall method. async.waterfall([ function(callback) { ... callback(err); }, function(result, callback) { console.log("This function should not be executed"); } ], function(err) { if (err) { next(err); return; } } ); But the second function always execute. How to prevent it? 回答1: Try adding a return async.waterfall([ function(callback) { ... return callback(err); //note return here }, function(result, callback) { console.log("This function should not be executed

Node.js, the pyramid of doom (even with async), can you write it better?

五迷三道 提交于 2019-12-30 11:32:13
问题 I consider myself a very experienced node.js developer. Yet I still wonder if there is a better way to write the following code so I don't get the pyramid of doom... Now I went easy on you, I have some code that my pyramid gets as high as 20 floors, no kidding; and that's WITH using async.js !!! The problem is really that I have many dependencies on previews variables so everything must be nested. The guy that wrote the book "Async Javascript, build more responsive Apps with less code"

How do I pass a standard set of parameters to each function in an async.js series?

旧城冷巷雨未停 提交于 2019-12-30 10:35:36
问题 Given the following node.js module, how would I call the functions in the array orderedListOfFunctions passing each one the response variable? var async = require("async"); var one = require("./one.js"); var two = require("./two.js"); module.exports = function (options) { var orderedListOfFunctions = [ one, two ]; return function (request, response, next) { // This is where I'm a bit confused... async.series(orderedListOfFunctions, function (error, returns) { console.log(returns); next(); });

How do I pass a standard set of parameters to each function in an async.js series?

三世轮回 提交于 2019-12-30 10:35:16
问题 Given the following node.js module, how would I call the functions in the array orderedListOfFunctions passing each one the response variable? var async = require("async"); var one = require("./one.js"); var two = require("./two.js"); module.exports = function (options) { var orderedListOfFunctions = [ one, two ]; return function (request, response, next) { // This is where I'm a bit confused... async.series(orderedListOfFunctions, function (error, returns) { console.log(returns); next(); });

How to make async code into sync inside the async.parallel method - NodeJs

妖精的绣舞 提交于 2019-12-25 03:19:07
问题 My backend code looks like: exports.getDashboard = (req, res) => { const dashboard = {}; const query = {}; let start; let end; async.parallel([ (callback) => { const { role } = req.user; switch (role) { case 'Admin': console.log('case admin is working >> >> >> >> >> >> >> >> >> >> '); start = moment().startOf('day'); // set to 12:00 am today end = moment().endOf('day'); // set to 23:59 pm today query.where = { entryTime: { $gt: start, $lt: end, }, }; break; case 'Manager': console.log('case

Optional callback not being called in the node.js async module's forEachOf method

旧街凉风 提交于 2019-12-24 13:14:08
问题 I'm using the async module's forEachOf method to print the end result after iterating through an object. Here is a shortened version of what I'm doing: var async = require('async'), cheerio = require('cheerio'), request = require('request'); var returnArray = []; async.forEachOf(myObj, function (value, key, callback) { var anotherObj = {}; anotherObj.type = "val1"; request(someurl, function(err, res, body) { if (err) { return callback(err); } var $ = cheerio.load(body); anotherObj.name =