Reputation: 5997
Can Instances of Node.js EventEmitter
class, listen to the event notifications from different platforms such as C or C++?
Upvotes: 0
Views: 250
Reputation: 1546
If you want implement platform-independent event system you may look to any message broker such as RabbitMQ. Or you can implement it using Redis PUB/SUB.
Upvotes: 2
Reputation: 1123
If you create an EventEmitter
you have to emit the event on this instance. If you want to trigger events in C/C++ you have to write an interface for it. You will find a starting points in the node-gyp repo.
Upvotes: 2
Reputation: 707696
Can Instances of Node.js
EventEmitter
class, listen to the event notifications from different platforms such as C or C++?
No, not directly. A node.js EventEmitter
class only works in Javascript (its implementation is entirely Javascript) so in order to trigger an event, some Javascript must call .emit()
in Javascript on the EventEmitter object in your node.js process.
If you had some C or C++ code running somewhere and you wanted to trigger an event in an EventEmitter
, then you'd have to somehow call some Javascript code in node.js from your C/C++ code that could then call a method (in Javascript) on the EventEmmitter
object.
If your C/C++ code was inside a node.js native code add-on, then you could probably trigger some sort of callback into Javascript from your C/C++ code the same way other node internals that are implemented in C/C++ can trigger callbacks (such as the implementation of setTimeout()
). If your C/C++ code was in another process (e.g. not inside of node.js already), then you'd have to do some sort of inter-process communication to the node.js process (like an http request) to connect to some code in node.js to ask it to do something on your behalf (like emit an event).
Upvotes: 1