@lodestar/beacon-node
Version:
A Typescript implementation of the beacon chain
21 lines • 880 B
JavaScript
export function getEventsApi({ chain, }) {
return {
async eventstream({ topics, signal, onEvent }) {
const onAbortFns = [];
for (const topic of topics) {
// biome-ignore lint/suspicious/noExplicitAny: We need to use `any` type here
const handler = (data) => {
// TODO: What happens if this handler throws? Does it break the other chain.emitter listeners?
onEvent({ type: topic, message: data });
};
chain.emitter.on(topic, handler);
onAbortFns.push(() => chain.emitter.off(topic, handler));
}
signal.addEventListener("abort", () => {
for (const abortFn of onAbortFns)
abortFn();
}, { once: true });
},
};
}
//# sourceMappingURL=index.js.map