Tag: asynchronous

如何显示连续的实时更新,如Facebook的股票,meetup.com主页呢?

如何显示连续的实时更新浏览器,如Facebook的股票,meetup.com主页呢? 在python,PHP,node.js和在服务器端的性能影响是什么? 如果页面被像akamai这样的CDNcaching,我们又怎么能实现同样的更新呢?

了解具有fs模块的Node JS生成器

我一直对Node JS非常兴奋。 我终于决定closures并编写一个testing项目,以了解Node最新的Harmony构build中的生成器。 这是我非常简单的testing项目: https://github.com/kirkouimet/project-node 要运行我的testing项目,您可以轻松地从Github中提取文件,然后运行它: node –harmony App.js 这是我的问题 – 我似乎无法让节点的asynchronousfs.readdir方法与内置的生成器运行。 其他项目,如银河和暂停似乎能够做到这一点。 这是我需要修复的代码块。 我想能够实例化FileSystemtypes的对象并调用其上的.list()方法: https://github.com/kirkouimet/project-node/blob/4c77294f42da9e078775bb84c763d4c60f21e1cc/FileSystem.js#L7-L11 FileSystem = Class.extend({ construct: function() { this.currentDirectory = null; }, list: function*(path) { var list = yield NodeFileSystem.readdir(path); return list; } }); 我需要提前做些什么来将节点的fs.readdir转换成一个生成器? 一个重要的注意事项是,我正在parsing创build的所有类函数。 这使我可以处理发电机的function,而不像普通的function https://github.com/kirkouimet/project-node/blob/4c77294f42da9e078775bb84c763d4c60f21e1cc/Class.js#L31-L51 这个项目我一直很难过。 会爱任何援助! 这是我想要完成的: 大量使用带有inheritance的John Resig的JavaScript Class支持修改版本的类 使用生成器获得对Node的asynchronous调用的内联支持 编辑 我试图实现你的例子function,我遇到了一些麻烦。 list: function*(path) { var […]

使用nodejsasynchronous和请求模块

我试图使用asynchronous和请求模块在一起,但我不明白如何通过callback。 我的代码是 var fetch = function(file, cb) { return request(file, cb); }; async.map(['file1', 'file2', 'file3'], fetch, function(err, resp, body) { // is this function passed as an argument to _fetch_ // or is it excecuted as a callback at the end of all the request? // if so how do i pass a callback to […]

Node.js:node.js中的http.get方法是否有同步版本?

node.js中有没有同步版本的http.get方法? 就像是: http.getSync({ host: 'google.com', port: 80, path: '/' }, function(response){ }); console.log(response) 有时候这会非常有用。

asynchronous初始化express.js(或类似的)应用程序

考虑一个例子:我有以下express.js应用程序(请参阅下面的代码片段)。 我想有一个持久连接到数据库,并且一个持久连接到我自己的服务(这需要asynchronous调用来启动)在整个应用程序生命周期。 还有几个入口点,即不仅可以通过HTTP协议访问我的应用程序。 当然,我想避免服务初始化代码重复,并可能有几个如同步初始化服务。 /* app.js */ var app = require('express')(); // set views, use routes, etc. var db = require('monk/mongoose/etc')(…); // happily, usually it's a sync operation var myService = require('./myService'); // however, it's possible to have several such services myService.init(function(err, result) { // only here an initialization process is finished! }); module.exports.app = […]

使用node.js运行许多并行http请求

我的任务是将一个进程分成许多并行运行的小进程,分发给一些从机。 请求通过HTTP进入服务器,服务器把它分成一些发送给从属机器的subprocess,等待所有的从请求返回响应,然后将聚合结果整理成一个数据对象,作为顶级请求。 我认为node.js会很有用,但是因为它是单线程的,所以我不能确定这是否可行,或者是否会阻止等待每个请求返回,然后再转到下一个请求。 这是可能的node.js? 如果是这样,有人能指出我的方向吗? 即节点模块使用或概述如何完成? 谢谢你的帮助。

如何使Grunt等待任务完成后再运行另一个?

这是我的Gruntfile和输出 。 正如您在输出中看到的那样,有几个与asynchronous任务相关的问题: imagemin被称为,下一个直线前进。 这使得它的输出出现在任务的最后,有什么相当混乱的; build ,这是一个自定义任务,使用var done = this.async()并在完成命令后调用done() ; 但是,如果我单独运行任务,这只能正常工作。 用另一个任务运行它也会使其运行asynchronous; 随着build运行后, jasmine没有什么可testing,因此是无用的。 有没有办法解决这个问题?

Node.js /asynchronous – 如何避免与asynchronouscallback地狱?

我是在后端新Node.Js和JavaScript的Web开发。 我看到callback里面的callback可能是一个痛苦,有模块可以避免这种情况。 其中一个模块是async, https://github.com/caolan/async 我已经阅读了文档,但很难开始并理解如何去做。 例如,我有这个函数“check_aut_user”,我怎样才能转换这个代码使用asynchronous? function check_auth_user(username, password, done) { var client = new pg.Client("pg://user:pass@127.0.0.1/database"); client.connect(function(err) { // If not get the connection if(err) { return console.error('could not connect to postgres', err); } // Query the user table client.query('select * from "user" where username = $1 and password = $2', [username, password], function(err, result) […]

NodeJSasynchronous:callback已经被调用?

我在Node.JS中使用asynchronous模块来跟踪我的asynchronous调用。 但是,我收到一个错误 – “已经调用callback”。 有人可以帮我吗? async.each(data['results'], function(result, done) { if (result['twitter_id'] !== null) { //Isolate twitter handle var param = { "user.screen_name": result['twitter_id']} db.test4.find( param, function(err, users) { if( err ) { return done(err); } else if (!users) { res.send("No user found"); } else { users.forEach( function(Result) { twitter_ids.push(Result); //console.log(Result); done(); }); } }); } […]

Node.js:在继续之前等待循环中的callback

我有一个循环,它有一个asynchronous调用,callback。 为了能够继续前进,我需要callback来触发整个循环,然后显示循环的结果。 我试图控制这种方式的每一个方法都行不通(尝试过Step,Tame.js,async.js等等) – 关于如何前进的build议? array = ['test', 'of', 'file']; array2 = ['another', 'array']; for(i in array) { item = array[i]; document_ids = new Array(); for (i2 in array2) { item2 = array2[i2]; // look it up mongodb.find({item_name: item2}).toArray(function(err, documents { // because of async, // the code moves on and calls this back later […]