是否所有的Node.js回调函数异步? [英] Are all Node.js callback functions asynchronous?
问题描述
我正在学习的Node.js和所有我在每一个教程听到的是节点是异步的,没有-blocking!
我听说经常浏览器的JavaScript只是某些事情,如AJAX调用可以进行异步或(使用回调)...这是真的的Node.js的一样好,甚至都Node.js的回调非阻塞功能所做的异步/非阻塞?
在做异步/非阻塞所有Node.js的回调函数?
块引用>没有。只有I / O通常是异步的,但许多其他的回调是同步的。经常检查文档。
的异步函数的例子:
同步回调的例子:
- EventEmitter (取决于当事件被触发)
- 阵迭代样的方法
的forEach
- 阵
排序
比较回调- 字符串
替换
匹配回调另请参见是否所有的JavaScript回调异步?如果没有,我怎么知道这些?(包括其他一些例子)。
I'm working on learning Node.js and all I hear in every tutorial is "Node is asynchronous and no -blocking!"
I've heard in regular browser JavaScript only certain things such as AJAX calls can be made asynchronous or non-blocking (using callbacks)... Is this true of Node.js as well, or are all Node.js callback functions made asynchronous/non-blocking?
解决方案are all Node.js callback functions made asynchronous/non-blocking?
No. Only I/O is usually asynchronous, but many other callbacks are synchronous. Always check the docs.
Examples of async functions:
- Async Filesystem access (they have sync counterparts without callbacks, though)
- Timers (
setTimeout
)process.nextTick
,setImmediate
- most database connections
- network connections
- Promises
Examples of sync callbacks:
- EventEmitter (depends on when the event is fired)
- Array iteration methods like
forEach
- Array
sort
comparator callbacks- String
replace
match callbacksSee also Are all javascript callbacks asynchronous? If not, how do I know which are? (including some other examples).
这篇关于是否所有的Node.js回调函数异步?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!