MCPcopy
hub / github.com/socketio/socket.io / run

Method run

packages/socket.io/lib/namespace.ts:236–258  ·  view source on GitHub ↗

* Executes the middleware for an incoming client. * * @param socket - the socket that will get added * @param fn - last fn call in the middleware * @private

(
    socket: Socket<ListenEvents, EmitEvents, ServerSideEvents, SocketData>,
    fn: (err?: ExtendedError) => void,
  )

Source from the content-addressed store, hash-verified

234 * @private
235 */
236 private run(
237 socket: Socket<ListenEvents, EmitEvents, ServerSideEvents, SocketData>,
238 fn: (err?: ExtendedError) => void,
239 ) {
240 if (!this._fns.length) return fn();
241
242 const fns = this._fns.slice(0);
243
244 function run(i: number) {
245 fns[i](socket, (err) => {
246 // upon error, short-circuit
247 if (err) return fn(err);
248
249 // if no middleware left, summon callback
250 if (!fns[i + 1]) return fn();
251
252 // go on to next
253 run(i + 1);
254 });
255 }
256
257 run(0);
258 }
259
260 /**
261 * Targets a room when emitting.

Callers 1

_addMethod · 0.95

Calls 2

fnFunction · 0.85
runFunction · 0.85

Tested by

no test coverage detected