Creates a new ØMQ observer. It should not be necessary to instantiate a new observer. Access an existing observer for a socket with Socket.events.
const socket = new Publisher()
const events = socket.events
The socket to observe.
Readonly
closedWhether the observer was closed, either manually or because the associated socket was closed.
Asynchronously iterate over socket events. When the socket is closed or when the observer is closed manually with Observer.close(), the iterator will return.
for await (event of socket.events) {
switch (event.type) {
case "bind":
console.log(`Socket bound to ${event.address}`)
break
// ...
}
}
Removes the specified listener function from the list of functions to call when the given event is observed.
The type of event that the listener was listening for.
The previously registered listener function.
Adds a listener function which will be invoked when the given event type is observed. Calling this method will convert the Observer to event emitter mode, which will make it impossible to call Observer.receive() at the same time.
socket.events.on("bind", event => {
console.log(`Socket bound to ${event.address}`)
// ...
})
The type of event to listen for.
The listener function that will be called with all event data when the event is observed.
Waits for the next event to become availeble on the observer. Reads an event immediately if possible. If no events are queued, it will wait asynchonously. The promise will be resolved with the next event when available.
When reading events with receive() the observer may not be in event emitter mode. Avoid mixing calls to receive() with event handlers via attached with on().
for await (event of socket.events) {
switch (event.type) {
case "bind":
console.log(`Socket bound to ${event.address}`)
break
// ...
}
}
Resolved with the next event and its details. See Event.
An event observer for ØMQ sockets. This starts up a ZMQ monitoring socket internally that receives all socket events. The event observer can be used in one of two ways, which are mutually exclusive: with receive() or with event listeners attached with on().