mirror of
https://github.com/oven-sh/bun
synced 2026-02-13 20:39:05 +00:00
* initial event emitter reimplementation * implement most of node:events. tests passing * work on emitter * fix importing node:events * work on event emitter tests * event work * event work * event stuff and experimenting with a lazy createHash * cleanup crypto stuff i had on this branch * finish event stuff up * fix error monitor * validate listeners are functions * changes requested
32 lines
787 B
JavaScript
32 lines
787 B
JavaScript
import EventEmitter3 from "eventemitter3";
|
|
import { group } from "mitata";
|
|
import EventEmitterNative from "node:events";
|
|
|
|
export const implementations = [
|
|
{
|
|
EventEmitter: EventEmitterNative,
|
|
name: process.isBun ? (EventEmitterNative.init ? "bun" : "C++") : "node:events",
|
|
monkey: true,
|
|
},
|
|
// { EventEmitter: EventEmitter3, name: "EventEmitter3" },
|
|
].filter(Boolean);
|
|
|
|
for (const impl of implementations) {
|
|
impl.EventEmitter?.setMaxListeners?.(Infinity);
|
|
}
|
|
|
|
export function groupForEmitter(name, cb) {
|
|
if (implementations.length === 1) {
|
|
return cb({
|
|
...implementations[0],
|
|
name: `${name}: ${implementations[0].name}`,
|
|
});
|
|
} else {
|
|
return group(name, () => {
|
|
for (let impl of implementations) {
|
|
cb(impl);
|
|
}
|
|
});
|
|
}
|
|
}
|