Front of the asynchronous flow (very important)
- Traditional native asynchronous
- Callback
- event
- Using asynchronous workflow tools (others packaged stuff)
- es6 Promise
Promise 是异步编程的一种解决方案,比传统的解决方案–回调函数和事件--更合理和更强大。它由社区最早提出和实现,ES6将其写进了语言标准,统一了语法,原生提供了Promise 所谓Promise ,简单说就是一个容器,里面保存着某个未来才回结束的事件(通常是一个异步操作)的结果。从语法上说,Promise是一个对象,从它可以获取异步操作的消息。 Promise 对象的状态不受外界影响 三种状态: pending:进行中 fulfilled :已经成功 rejected 已经失败 状态改变: Promise对象的状态改变,只有两种可能: 从pending变为fulfilled 从pending变为rejected。 这两种情况只要发生,状态就凝固了,不会再变了,这时就称为resolved(已定型)
- es6 generator function
- es6 (7) async function
- node.js in nextTick setImmudiate
nextTick()的回调函数执行的优先级要高于setImmediate(); process.nextTick()属于idle观察者,setImmediate()属于check观察者.在每一轮循环检查中,idle观察者先于I/O观察者,I/O观察者先于check观察者. 在具体实现上,process.nextTick()的回调函数保存在一个数组中, setImmediate()的结果则是保存在链表中. 在行为上,process.nextTick()在每轮循环中会将数组中的回调函数全部执行完. 而setImmediate()在每轮循环中执行链表中的一个回调函数. nextTick > 回调函数 > setImmediate
- Third-party library async.js
Summary:
asynchronous processes asynchronous task is placed in the queue, the queue only take asynchronous execution after executing the main thread
3. References
-
Promise
https://blog.csdn.net/MrJavaweb/article/details/79475949 -
Async-await
-
Node.js in nextTick () and setimmediate ()
https://www.cnblogs.com/5ishare/p/5268273.html -
async library
https://caolan.github.io/async/
Reference Documents
Event-Loop
http://www.ruanyifeng.com/blog/2014/10/event-loop.html?bsh_bid=983729729
history of the most easy to read and understand Promise / A + fully realized
https://zhuanlan.zhihu.com / p / 21834559