node.js - nodejs的事件回调机制是否属于设计模式中的某一种?
PHPz
PHPz 2017-04-17 11:26:49
0
3
662

属于观察者模式吗?那么谁是观察者?谁是被观察者?

PHPz
PHPz

学习是最好的投资!

reply all(3)
阿神

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 基于观察者模式’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

黄舟

It should be proactor, right?

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template