* Executes the middleware for an incoming event. * * @param {Array} event - event that will get emitted * @param {Function} fn - last fn call in the middleware * @private
(event: Event, fn: (err: Error | null) => void)
| 962 | * @private |
| 963 | */ |
| 964 | private run(event: Event, fn: (err: Error | null) => void): void { |
| 965 | const fns = this.fns.slice(0); |
| 966 | if (!fns.length) return fn(null); |
| 967 | |
| 968 | function run(i: number) { |
| 969 | fns[i](event, function (err) { |
| 970 | // upon error, short-circuit |
| 971 | if (err) return fn(err); |
| 972 | |
| 973 | // if no middleware left, summon callback |
| 974 | if (!fns[i + 1]) return fn(null); |
| 975 | |
| 976 | // go on to next |
| 977 | run(i + 1); |
| 978 | }); |
| 979 | } |
| 980 | |
| 981 | run(0); |
| 982 | } |
| 983 | |
| 984 | /** |
| 985 | * Whether the socket is currently disconnected |