
Security News
TeamPCP and BreachForums Launch $1,000 Contest for Supply Chain Attacks
TeamPCP and BreachForums are promoting a Shai-Hulud supply chain attack contest with a $1,000 prize for the biggest package compromise.
@devgrid/async-emitter
Advanced tools
A powerful asynchronous event emitter built on top of eventemitter3, providing parallel, serial, and reduce event emission patterns with concurrency control.
npm install @devgrid/async-emitter
# or
yarn add @devgrid/async-emitter
import { AsyncEventEmitter } from '@devgrid/async-emitter';
const emitter = new AsyncEventEmitter();
// Add async listener
emitter.on('event', async (data) => {
await someAsyncOperation(data);
});
// Emit event and wait for all listeners
await emitter.emitParallel('event', 'some data');
Execute all listeners concurrently:
const emitter = new AsyncEventEmitter();
emitter.on('parallel', async () => {
await delay(100);
console.log('First listener');
});
emitter.on('parallel', async () => {
await delay(50);
console.log('Second listener');
});
// Both listeners execute simultaneously
await emitter.emitParallel('parallel');
Execute listeners one after another:
const emitter = new AsyncEventEmitter();
emitter.on('serial', async (value) => {
await delay(100);
return value + 1;
});
emitter.on('serial', async (value) => {
await delay(50);
return value * 2;
});
// Listeners execute sequentially
const results = await emitter.emitSerial('serial', 1);
console.log(results); // [2, 2]
Process events with accumulated results:
const emitter = new AsyncEventEmitter();
// Left to right reduction
emitter.on('reduce', async (value) => value + 1);
emitter.on('reduce', async (value) => value * 2);
const result = await emitter.emitReduce('reduce', 1);
console.log(result); // 4 ((1 + 1) * 2)
// Right to left reduction
const rightResult = await emitter.emitReduceRight('reduce', 1);
console.log(rightResult); // 3 (1 * 2 + 1)
Limit the number of concurrent listener executions:
const emitter = new AsyncEventEmitter(2); // Max 2 concurrent executions
// Or set concurrency later
emitter.setConcurrency(3);
emitter.on('concurrent', async () => {
await heavyOperation();
});
// Only 2/3 listeners will execute simultaneously
await emitter.emitParallel('concurrent');
const emitter = new AsyncEventEmitter();
// Using once
emitter.once('single', async () => {
console.log('Called only once');
});
// Using subscribe with once option
const unsubscribe = emitter.subscribe('single', async () => {
console.log('Also called only once');
}, true);
// Manual unsubscribe if needed
unsubscribe();
const emitter = new AsyncEventEmitter();
const cleanup = emitter.subscribe('event', async () => {
console.log('Event handled');
});
// Later, when you need to remove the listener
cleanup();
Thanks to eventemitter3, this library works seamlessly in browsers:
<!-- Using via CDN -->
<script src="https://unpkg.com/eventemitter3/umd/eventemitter3.min.js"></script>
<script src="path/to/async-emitter.js"></script>
<script>
const emitter = new AsyncEventEmitter();
emitter.on('click', async () => {
await fetch('/api/endpoint');
});
document.getElementById('button').addEventListener('click', () => {
emitter.emitParallel('click');
});
</script>
Using with bundlers:
// webpack/rollup/esbuild will handle it automatically
import { AsyncEventEmitter } from '@devgrid/async-emitter';
new AsyncEventEmitter(concurrency?: number)
class AsyncEventEmitter {
// Emission patterns
emitParallel(event: string, ...args: any[]): Promise<any[]>
emitSerial(event: string, ...args: any[]): Promise<any[]>
emitReduce(event: string, ...args: any[]): Promise<any>
emitReduceRight(event: string, ...args: any[]): Promise<any>
// Listener management
on(event: string, listener: Function): this
once(event: string, listener: Function): this
removeListener(event: string, listener: Function): this
subscribe(event: string, listener: Function, once?: boolean): () => void
// Configuration
setConcurrency(concurrency: number): this
}
import { isAsyncEventEmitter } from '@devgrid/async-emitter';
if (isAsyncEventEmitter(obj)) {
// obj is an AsyncEventEmitter instance
}
MIT
Built with eventemitter3 for cross-platform event emission.
FAQs
Async event emitter
We found that @devgrid/async-emitter demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer 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
TeamPCP and BreachForums are promoting a Shai-Hulud supply chain attack contest with a $1,000 prize for the biggest package compromise.

Security News
Packagist urges PHP projects to update Composer after a GitHub token format change exposed some GitHub Actions tokens in CI logs.

Research
GemStuffer abuses RubyGems as an exfiltration channel, packaging scraped UK council portal data into junk gems published from new accounts.