阿神2017-04-17 11:28:49
This is called reactor mode
Speaking of asynchronous IO, it is actually difficult to achieve true asynchronous now (unless the potential of the hardware is used for asynchronous triggering). In most cases, it is still necessary to block in a multiplexed function, such as select or epoll, and wait until the descriptor Ready (for example, the network card buffer is readable and writable), and then calls the callback function registered on the corresponding descriptor. This approach is the basic idea of current reactor design. Use Twisted’s picture to explain
阿神2017-04-17 11:28:49
event-driven is 基于观察者模式
’s
http://www.dofactory.com/javascript/observer-design-pattern
Event handler is 观察者
, event source is 被观察者
The idea of the observer pattern is: 被观察者
Maintain a list of a series of 观察者
s, and when the theme changes, 通知
all observers
This notification mechanism is implemented in JavaScript in the form of callback
, which is completely in line with the design concept of the observer pattern