added experimentation with events

This commit is contained in:
SrGooglo 2025-04-09 20:42:28 +00:00
parent 92943f8203
commit b94e18fdd0

View File

@ -0,0 +1,21 @@
export default class WSEvent {
constructor(fn, middlewares = []) {
this.fn = fn
this.middlewares = middlewares
}
execute = async (socket, body) => {
try {
// execute middlewares
for await (const middleware of this.middlewares) {
await middleware(socket, body)
}
await this.fn(socket, body)
} catch (error) {
await this.onError(socket, body, error)
}
}
onError = async (socket, body, error) => {}
}