Advertisement
sergeyampo

Clousre in EventEmitter

Jun 2nd, 2020
1,150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     private handleSignals(
  2.         proc: NodeJS.Process,
  3.         signals: NodeJS.Signals[],
  4.         errorToCallbacks: Map<EProcessError | EProcessSignals, Array<() => void>>,
  5.     ): void {
  6.         let currCloseCbs: Array<() => void> = [() => {}];
  7.         for (const sig of signals) {
  8.             currCloseCbs = errorToCallbacks.get(sig as EProcessSignals); //does this array of callbacks of this iteration<
  9.             proc.on(sig, (): void => {
  10.                 ...
  11.                 currCloseCbs.map((cb) => cb()); //will be a closure while calling this
  12.                 ...
  13.             });
  14.         }
  15.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement