Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
web3-core-promievent
Advanced tools
This package extends eventEmitters with promises to allow chaining as well as multiple final states of a function.
The web3-core-promievent package is a part of the Web3.js library, which is used to interact with the Ethereum blockchain. This specific package provides a hybrid of Promise and EventEmitter, allowing developers to handle asynchronous operations with both promises and events.
Creating a PromiEvent
This code demonstrates how to create a PromiEvent that emits an event and resolves a promise after an asynchronous operation.
const PromiEvent = require('web3-core-promievent');
function asyncOperation() {
const promiEvent = new PromiEvent();
setTimeout(() => {
promiEvent.eventEmitter.emit('done', 'Operation completed');
promiEvent.resolve('Success');
}, 1000);
return promiEvent.eventEmitter;
}
asyncOperation().on('done', (message) => {
console.log(message);
}).then((result) => {
console.log(result);
});
Handling Errors
This code demonstrates how to handle errors in a PromiEvent by emitting an error event and rejecting the promise.
const PromiEvent = require('web3-core-promievent');
function asyncOperationWithError() {
const promiEvent = new PromiEvent();
setTimeout(() => {
promiEvent.eventEmitter.emit('error', new Error('Operation failed'));
promiEvent.reject(new Error('Failure'));
}, 1000);
return promiEvent.eventEmitter;
}
asyncOperationWithError().on('error', (error) => {
console.error(error.message);
}).catch((error) => {
console.error(error.message);
});
Listening to Multiple Events
This code demonstrates how to listen to multiple events emitted by a PromiEvent during an asynchronous operation.
const PromiEvent = require('web3-core-promievent');
function asyncOperationWithMultipleEvents() {
const promiEvent = new PromiEvent();
setTimeout(() => {
promiEvent.eventEmitter.emit('step', 'Step 1 completed');
promiEvent.eventEmitter.emit('step', 'Step 2 completed');
promiEvent.resolve('All steps completed');
}, 1000);
return promiEvent.eventEmitter;
}
asyncOperationWithMultipleEvents().on('step', (message) => {
console.log(message);
}).then((result) => {
console.log(result);
});
Bluebird is a fully featured promise library with focus on innovative features and performance. It provides a wide range of utilities for working with promises, including event handling, which makes it somewhat comparable to web3-core-promievent.
EventEmitter3 is a high performance EventEmitter that is used for handling events in JavaScript. While it does not provide promise functionality out of the box, it can be combined with promises to achieve similar results to web3-core-promievent.
RxJS is a library for reactive programming using Observables, to make it easier to compose asynchronous or callback-based code. It provides powerful event handling and asynchronous data stream capabilities, which can be used similarly to web3-core-promievent.
This is a sub package of web3.js
This is the PromiEvent package is used to return a EventEmitter mixed with a Promise to allow multiple final states as well as chaining. Please read the documentation for more.
npm install web3-core-promievent
import PromiEvent from 'web3-core-promievent';
new PromiEvent();
All the typescript typings are placed in the types folder.
FAQs
This package extends the EventEmitter with the Promise class to allow chaining as well as multiple final states of a function.
The npm package web3-core-promievent receives a total of 350,688 weekly downloads. As such, web3-core-promievent popularity was classified as popular.
We found that web3-core-promievent demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 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.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.