You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To be able to make every emitted event somewhere in a component available in all worker threads (if implemented, see #6), a custom/intercepted .emit(...) method is needed.
Either use a Proxy or a custom EventEmitter class.
Proxy approach (quick ChatGPT asked):
constEventEmitter=require('events');// Erstellen einer neuen EventEmitter-InstanzconstmyEmitter=newEventEmitter();// Proxy-Handler erstellenconsthandler={apply: function(target,thisArg,argumentsList){const[eventName, ...args]=argumentsList;console.log(`Event emitted: ${eventName}`,args);// Aufruf der originalen emit-MethodereturnReflect.apply(target,thisArg,argumentsList);}};// Proxy für die emit-Methode erstellenmyEmitter.emit=newProxy(myEmitter.emit,handler);// BeispielereignissemyEmitter.emit('event1','data1');myEmitter.emit('event2',{key: 'value'});myEmitter.emit('event3',42);
const{ EventEmitter }=require("events");module.exports=classEventsextendsEventEmitter{constructor(...args){super(...args);}staticsymbol=Symbol("register");staticevents=newSet();emit(event, ...args){// is the code below even necessary?// if we hook into the `.emit` method// we could just use this here to "broadcast" into child/plugin/worker// change `static symbol...` to `static broadcast = Symbol("broadcast")`// and emit events as symbol: `super.emit(Events.broadcast, ...)`// some where, where the main/worker communication is handeld, listen then for `Events.on(Events.broadcast, ...)`if(!Events.events.has(event)){Events.events.add(event);process.nextTick(()=>{super.emit(Events.symbol,event, ...args);});}returnsuper.emit(event, ...args);}};
To be able to make every emitted event somewhere in a component available in all worker threads (if implemented, see #6), a custom/intercepted
.emit(...)
method is needed.Either use a Proxy or a custom
EventEmitter
class.Proxy approach (quick ChatGPT asked):
EventEmitter class approach (quick written here)
The text was updated successfully, but these errors were encountered: