proxy-signals.js 997 B

12345678910111213141516171819202122232425262728293031323334
  1. import { allSignals } from './all-signals.js';
  2. /**
  3. * Starts forwarding signals to `child` through `parent`.
  4. */
  5. export const proxySignals = (child) => {
  6. const listeners = new Map();
  7. for (const sig of allSignals) {
  8. const listener = () => {
  9. // some signals can only be received, not sent
  10. try {
  11. child.kill(sig);
  12. /* c8 ignore start */
  13. }
  14. catch (_) { }
  15. /* c8 ignore stop */
  16. };
  17. try {
  18. // if it's a signal this system doesn't recognize, skip it
  19. process.on(sig, listener);
  20. listeners.set(sig, listener);
  21. /* c8 ignore start */
  22. }
  23. catch (_) { }
  24. /* c8 ignore stop */
  25. }
  26. const unproxy = () => {
  27. for (const [sig, listener] of listeners) {
  28. process.removeListener(sig, listener);
  29. }
  30. };
  31. child.on('exit', unproxy);
  32. return unproxy;
  33. };
  34. //# sourceMappingURL=proxy-signals.js.map