NodeJS async.parallel成功被调用两次?
看我的代码
router.get('/:productSlug', function(req, res, next) { async.parallel({ product: function(callback) { products.single(callback, req,res,next) } }, function(err, results){ console.log('HERE'); console.log(results.product.rows[0]); res.render('product', {product : results.product.rows[0]}); }); });
我的控制台输出如下
HERE { name: 'Test Product', price: '19.99' } GET /img/logo.png 304 9.127 ms - - GET /img/social/share.png 304 2.051 ms - - GET /img/social/tweet.png 304 2.190 ms - - HERE undefined
所以它的工作,但似乎是再次调用它,第二个电话是意义不明确的部分,使整个事情破裂。
任何想法 – 我完全失去了!
编辑:添加被称为…的function
single: function (callback, req, res, next){ var client = new req.app.locals.pg.Client(req.app.locals.pgCon); client.connect(function(err) { if(err) { return callback(['could not connect to postgres', err], null); } client.query('SELECT * FROM products WHERE slug=$1', [req.params.productSlug], function(err, result) { if(err) { return callback(['error running query', err], null); } return callback(null, result) client.end(); }); }); }, //End function : single
在浏览器中打开页面时,会向/favacon.ico
发送附加请求 – 请务必处理。
- 使用stream作为Node.js中的asynchronous队列的input,如何确保queue.drain只被调用一次
- 无法理解ASYNC npm包中的ASYNC系列
- 如果将文件可写入stream传递给Node.js中的Console构造函数,是否正在向其写入asynchronous?
- 确定在Node.js中forEach中调用的最后一个asynchronous函数
- 在启动组件之前获取configuration参数
- Superagent在asynchronous瀑布中移动响应callback位置
- 在node.js中使用Async瀑布
- 如何跟踪node.js中的asynchronous/等待错误?
- 如何纠结Node.JS的asynchronous