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
I have a question regarding the execution order of middleware and event handlers in Socket.IO.
Here's my current setup:
const io = require('socket.io')(server);
io.on('connection', (socket) => {
console.log('A user connected');
// Middleware to process events
socket.use(([event, ...args], next) => {
console.log(`Middleware: Event received - ${event}`);
// Perform logging, authorization, rate limiting, etc.
next(); // Pass control to the next middleware or event handler
// Code here runs immediately after `next()`?
console.log(`Middleware: Post-processing after event - ${event}`);
});
// Event listeners
socket.on('example', (data) => {
console.log('Example event handler executed', data);
// Handle the 'example' event
});
socket.on('disconnect', () => {
console.log('User disconnected');
});
});
i want to know the codes after next function call in socket.use() runs immediately or wait all middlewares and event handler executed and then start to executing?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have a question regarding the execution order of middleware and event handlers in Socket.IO.
Here's my current setup:
i want to know the codes after next function call in socket.use() runs immediately or wait all middlewares and event handler executed and then start to executing?
Beta Was this translation helpful? Give feedback.
All reactions