循环有点糊涂!
不好解释, 直接上 Google 了 http://stackoverflow.com/questions/3272298/whats-an-event-loop-and-how-is-it-different-than-using-other-models http://nikhilm.github.io/uvbook/basics.html
简单的说法就是 Event Loop 是一中实现方式, 可以把操作作为函数注册在队列里, 然后每当有事件就遍历队列… 适当地调用对应的函数,
while there are still events to process: e = get the next event if there is a callback associated with e: call the callback
然后本来同步的代码可以这样写的, 问题是会阻塞代码执行, Pseudo example for blocking I/O:
row = db_query('SELECT * FROM some_table'); print(row);
就换成了异步的写法, 注册一个函数, 不会阻塞代码执行了… Pseudo example for non-blocking I/O:
db_query('SELECT * FROM some_table', function (row) { print(row); });
表示没看过 Node 源码, 不清楚具体实现… 话说 JS 没有把异步代码转同步的写法真是蛋疼啊
谢谢你先!
node要是转成同步了的话, 我就白从php转过来了.
http://reactphp.org/ php版Node nodephp 呵呵
CNode 社区为国内最专业的 Node.js 开源技术社区,致力于 Node.js 的技术研究。
不好解释, 直接上 Google 了 http://stackoverflow.com/questions/3272298/whats-an-event-loop-and-how-is-it-different-than-using-other-models http://nikhilm.github.io/uvbook/basics.html
简单的说法就是 Event Loop 是一中实现方式, 可以把操作作为函数注册在队列里, 然后每当有事件就遍历队列… 适当地调用对应的函数,
然后本来同步的代码可以这样写的, 问题是会阻塞代码执行, Pseudo example for blocking I/O:
就换成了异步的写法, 注册一个函数, 不会阻塞代码执行了… Pseudo example for non-blocking I/O:
表示没看过 Node 源码, 不清楚具体实现… 话说 JS 没有把异步代码转同步的写法真是蛋疼啊
谢谢你先!
node要是转成同步了的话, 我就白从php转过来了.
http://reactphp.org/ php版Node nodephp 呵呵