Security News
Supply Chain Attack Detected in Solana's web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Ultron is high-intelligence robot. It gathers intel so it can start improving upon his rudimentary design
Ultron is a high-intelligence, non-blocking event emitter wrapper for Node.js. It simplifies the process of adding and removing event listeners, ensuring that listeners are properly cleaned up to prevent memory leaks.
Adding Event Listeners
This feature allows you to add event listeners to an event emitter. The code sample demonstrates how to create an Ultron instance and add an event listener to an event emitter.
const Ultron = require('ultron');
const EventEmitter = require('events');
const emitter = new EventEmitter();
const ultron = new Ultron(emitter);
ultron.on('event', () => {
console.log('Event triggered');
});
emitter.emit('event');
Removing Event Listeners
This feature allows you to remove specific event listeners from an event emitter. The code sample demonstrates how to add and then remove an event listener using Ultron.
const Ultron = require('ultron');
const EventEmitter = require('events');
const emitter = new EventEmitter();
const ultron = new Ultron(emitter);
function onEvent() {
console.log('Event triggered');
}
ultron.on('event', onEvent);
ultron.remove('event', onEvent);
emitter.emit('event');
Removing All Event Listeners
This feature allows you to remove all event listeners from an event emitter. The code sample demonstrates how to add multiple event listeners and then remove all of them using the `destroy` method.
const Ultron = require('ultron');
const EventEmitter = require('events');
const emitter = new EventEmitter();
const ultron = new Ultron(emitter);
ultron.on('event1', () => {
console.log('Event 1 triggered');
});
ultron.on('event2', () => {
console.log('Event 2 triggered');
});
ultron.destroy();
emitter.emit('event1');
emitter.emit('event2');
EventEmitter3 is a high-performance event emitter for Node.js and the browser. It provides a similar interface to Node.js's built-in EventEmitter but with better performance and additional features. Unlike Ultron, EventEmitter3 does not provide automatic cleanup of event listeners.
Mitt is a tiny (~200 bytes) functional event emitter. It is designed to be simple and fast, making it suitable for use in both Node.js and browser environments. Mitt does not offer the same level of automatic listener management as Ultron.
Component-emitter is a simple event emitter component for the browser and Node.js. It provides a minimalistic API for adding and removing event listeners. Unlike Ultron, it does not include built-in mechanisms for managing listener cleanup.
Ultron is a high-intelligence robot. It gathers intelligence so it can start improving upon his rudimentary design. It will learn your event emitting patterns and find ways to exterminate them. Allowing you to remove only the event emitters that you assigned and not the ones that your users or developers assigned. This can prevent race conditions, memory leaks and even file descriptor leaks from ever happening as you won't remove clean up processes.
The module is designed to be used in browsers using browserify and in Node.js. You can install the module through the public npm registry by running the following command in CLI:
npm install --save ultron
In all examples we assume that you've required the library as following:
'use strict';
var Ultron = require('ultron');
Now that we've required the library we can construct our first Ultron
instance.
The constructor requires one argument which should be the EventEmitter
instance that we need to operate upon. This can be the EventEmitter
module
that ships with Node.js or EventEmitter3
or anything else as long as it
follow the same API and internal structure as these 2. So with that in mind we
can create the instance:
//
// For the sake of this example we're going to construct an empty EventEmitter
//
var EventEmitter = require('events').EventEmitter; // or require('eventmitter3');
var events = new EventEmitter();
var ultron = new Ultron(events);
You can now use the following API's from the Ultron instance:
Register a new event listener for the given event. It follows the exact same API
as EventEmitter.on
but it will return itself instead of returning the
EventEmitter instance. If you are using EventEmitter3 it also supports the
context param:
ultron.on('event-name', handler, { custom: 'function context' });
Just like you would expect, it can also be chained together.
ultron
.on('event-name', handler)
.on('another event', handler);
Exactly the same as the Ultron.on but it only allows the execution once.
Just like you would expect, it can also be chained together.
ultron
.once('event-name', handler, { custom: 'this value' })
.once('another event', handler);
This is where all the magic happens and the safe removal starts. This function accepts different argument styles:
removeAllListeners()
API.
and ,
to create a
list of events that need to be cleared.ultron.remove('foo, bar baz'); // Removes foo, bar and baz.
ultron.remove('foo', 'bar', 'baz'); // Removes foo, bar and baz.
ultron.remove(); // Removes everything.
If you just want to remove a single event listener using a function reference
you can still use the EventEmitter's removeListener(event, fn)
API:
function foo() {}
ultron.on('foo', foo);
events.removeListener('foo', foo);
MIT
FAQs
Ultron is high-intelligence robot. It gathers intel so it can start improving upon his rudimentary design
We found that ultron demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.