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
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
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
event-driven is
基于观察者模式
’shttp://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 observersThis notification mechanism is implemented in JavaScript in the form of
callback
, which is completely in line with the design concept of the observer patternIt should be proactor, right?