How to use signal-exit - 10 common examples

To help you get started, we’ve selected a few signal-exit examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vadimdemedes / ink / src / instance.js View on Github external
// so that it's rerendered every time, not just new static parts, like in non-debug mode
		this.fullStaticOutput = '';

		if (options.experimental) {
			this.container = experimentalReconciler.createContainer(this.rootNode, false, false);
		} else {
			this.container = reconciler.createContainer(this.rootNode, false, false);
		}

		this.exitPromise = new Promise((resolve, reject) => {
			this.resolveExitPromise = resolve;
			this.rejectExitPromise = reject;
		});

		// Unmount when process exits
		this.unsubscribeExit = signalExit(this.unmount, {alwaysLast: false});
	}
github rollup / rollup / cli / run / watch.ts View on Github external
);
					if (event.result && event.result.getTimings) {
						printTimings(event.result.getTimings());
					}
					break;

				case 'END':
					if (!silent && isTTY) {
						stderr(`\n[${dateTime()}] waiting for changes...`);
					}
			}
		});
	}

	// catch ctrl+c, kill, and uncaught errors
	const removeOnExit = onExit(close);
	process.on('uncaughtException', close);

	// only listen to stdin if it is a pipe
	if (!process.stdin.isTTY) {
		process.stdin.on('end', close); // in case we ever support stdin!
	}

	function close(err: Error) {
		removeOnExit();
		process.removeListener('uncaughtException', close);
		// removing a non-existent listener is a no-op
		process.stdin.removeListener('end', close);

		if (watcher) watcher.close();

		if (configWatcher) configWatcher.close();
github EvanBacon / react-native-ink / src / modules / Instance / index.tsx View on Github external
this.container = experimentalReconciler.createContainer(
        this.rootNode,
        false,
        false,
      );
    } else {
      this.container = reconciler.createContainer(this.rootNode, false, false);
    }

    this.exitPromise = new Promise((resolve, reject) => {
      this.resolveExitPromise = resolve;
      this.rejectExitPromise = reject;
    });

    // Unmount when process exits
    this.unsubscribeExit = signalExit(this.unmount, { alwaysLast: false });
  }
github smooth-code / jest-puppeteer / packages / spawnd / src / index.js View on Github external
function spawnd(command, options) {
  function cleanExit(code = 1) {
    if (proc && proc.pid) {
      treeKill(proc.pid, () => exit(code))
    } else {
      exit(code)
    }
  }

  const proc = spawn(command, options)
  proc.stderr.pipe(process.stderr)
  proc.on('exit', cleanExit)
  proc.on('error', () => cleanExit(1))

  const removeExitHandler = onExit(code => {
    cleanExit(typeof code === 'number' ? code : 1)
  })

  proc.destroy = async () => {
    removeExitHandler()
    proc.removeAllListeners('exit')
    proc.removeAllListeners('error')
    return pTreeKill(proc.pid).catch(() => {
      /* ignore error */
    })
  }

  return proc
}
github nuxt / tib / src / browsers / browser.js View on Github external
async start(capabilities, ...args) {
    await this.callHook('start:before')

    try {
      await this._start(capabilities, ...args)

      await this.callHook('start:after', this.driver)

      this.ready = true

      onExit(() => this.close())

      return this
    /* istanbul ignore next */
    } catch (e) {
      await this.close()

      throw new BrowserError(e)
    }
  }
github nuxt / nuxt.js / packages / utils / src / locking.js View on Github external
options.onCompromised = (err) => {
      onCompromised(err)
      lockWasCompromised = true
    }

    release = await properlock.lock(lockPath, options)
  } catch (e) {}

  if (!release) {
    consola.warn(`Unable to get a lock with id '${id}' on ${dir} (but will continue)`)
    return false
  }

  if (!lockPaths.size) {
    // make sure to always cleanup our temporate lockPaths
    onExit(() => {
      for (const lockPath of lockPaths) {
        fs.removeSync(lockPath)
      }
    })
  }

  lockPaths.add(lockPath)

  return async function lockRelease () {
    try {
      await fs.remove(lockPath)
      lockPaths.delete(lockPath)

      // release as last so the lockPath is still removed
      // when it fails on a compromised lock
      await release()
github preconstruct / preconstruct / packages / preconstruct / test-utils / fixturez.js View on Github external
}

  function cleanup() {
    let err;
    created.forEach(tempDir => {
      try {
        fsExtra.removeSync(tempDir);
      } catch (e) {
        err = e;
      }
    });
    created.length = 0;
    if (err) throw err;
  }

  onExit(cleanup);

  return {
    find,
    copy
  };
}
github ifiokjr / remirror / support / jest / puppeteer.ts View on Github external
export async function setupServer(globalConfig: Config.GlobalConfig) {
  await setup([server]);

  onExit(() =>
    Promise.all([teardown(), teardownPuppeteer()]).then(() => {
      process.exit();
    }),
  );

  await setupPuppeteer(globalConfig);
}
github jamiebuilds / glow / src / index.js View on Github external
export default async function glow(opts: GlowOptions) {
  let cwd = opts.cwd;
  let start = timers.now();

  onExit(() => {
    let end = timers.now();
    let seconds = timers.seconds(start, end);
    env.logger.info(env.lang.get('doneIn', seconds));
  });

  let flowConfigPath = await flow.getFlowConfigPath(cwd);

  if (!flowConfigPath) {
    throw startupError('noFlowConfig');
  }

  let flowRootDir = flow.getFlowRootDir(flowConfigPath);
  let flowConfig = await flow.getFlowConfig(flowRootDir);

  if (!flowConfig) {
    throw startupError(
github deepsweet / foxr / src / api / Foxr.ts View on Github external
const args = ['-marionette', '-safe-mode', '-no-remote']

    if (options.headless === true) {
      args.push('-headless')
    }

    if (Array.isArray(options.args)) {
      args.push(...options.args)
    }

    const firefoxProcess = execa(options.executablePath, args, {
      detached: true,
      stdio: options.dumpio ? 'inherit' : 'ignore'
    })

    onExit(() => {
      firefoxProcess.kill()
    })

    firefoxProcess.unref()

    await waitForPort(DEFAULT_HOST, DEFAULT_PORT)

    return this.connect(options)
  }
}

signal-exit

when you want to fire an event no matter how a process exits.

ISC
Latest version published 1 year ago

Package Health Score

80 / 100
Full package analysis

Popular signal-exit functions