![]() ![]() When the event ‘eventOne’ is emitted, both the above callbacks should be invoked. MyEmitter.on('eventOne', c2) // Register for eventOne MyEmitter.on('eventOne', c1) // Register for eventOne Example 1 - Create an event emitter instance and register a couple of callbacks const myEmitter = new EventEmitter() Ĭonsole.log('yet another event occurred!') In fact, if you replace our EventEmitter with Node.js’s built-in ‘events’ module you will get the same result. Please note that our code will mimic the exact API of the Node.js ‘events’ module. The above basic features are sufficient to implement a full system using the eventing model.īefore we get into the coding, let’s take a look at how we will be using the EventEmitter class. What we will be building in this tutorial It’s kind of like a pub/sub or observer design pattern (though not exactly). ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |