How to use node-graceful - 6 common examples

To help you get started, we’ve selected a few node-graceful 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 fgnass / instant / lib / index.js View on Github external
if (root && opts.watch !== false) {
      var urlsByFile = {}

      fn.watcher = filewatcher({ delay: opts.delay })

      // Stop the file system watcher so apps can exit gracefully when
      // terminated by Ctrl+c (SIGINT) or a polite termination request (SIGTERM).
      // You can also call the cleanUp() function directly to handle housekeeping
      // in your own server (e.g., when it is asked to close).
      fn.cleanUp = function (done) {
        fn.watcher.removeAll()
        done()
      }
      Graceful.timeout = 3000
      Graceful.on('SIGINT', fn.cleanUp)
      Graceful.on('SIGTERM', fn.cleanUp)

      // when a file is modifed tell all clients to reload it
      fn.watcher.on('change', function(file) {
        fn.reload(urlsByFile[file])
      })

      // build a RegExp to match all watched file extensions
      var exts = opts.watch || ['html', 'js', 'css']
        , re = new RegExp('\\.(' + exts.join('|') + ')$')

      // pass an `onfile` handler that watches matching files
      opts = Object.create(opts, {
        onfile: { value: function(path, stat) {
          if (!re.test(path)) return
          urlsByFile[path] = this.path
          this._maxage = 0
github fgnass / instant / lib / index.js View on Github external
if (root && opts.watch !== false) {
      var urlsByFile = {}

      fn.watcher = filewatcher({ delay: opts.delay })

      // Stop the file system watcher so apps can exit gracefully when
      // terminated by Ctrl+c (SIGINT) or a polite termination request (SIGTERM).
      // You can also call the cleanUp() function directly to handle housekeeping
      // in your own server (e.g., when it is asked to close).
      fn.cleanUp = function (done) {
        fn.watcher.removeAll()
        done()
      }
      Graceful.timeout = 3000
      Graceful.on('SIGINT', fn.cleanUp)
      Graceful.on('SIGTERM', fn.cleanUp)

      // when a file is modifed tell all clients to reload it
      fn.watcher.on('change', function(file) {
        fn.reload(urlsByFile[file])
      })

      // build a RegExp to match all watched file extensions
      var exts = opts.watch || ['html', 'js', 'css']
        , re = new RegExp('\\.(' + exts.join('|') + ')$')

      // pass an `onfile` handler that watches matching files
      opts = Object.create(opts, {
        onfile: { value: function(path, stat) {
          if (!re.test(path)) return
          urlsByFile[path] = this.path
github fgnass / instant / lib / index.js View on Github external
}

    if (root && opts.watch !== false) {
      var urlsByFile = {}

      fn.watcher = filewatcher({ delay: opts.delay })

      // Stop the file system watcher so apps can exit gracefully when
      // terminated by Ctrl+c (SIGINT) or a polite termination request (SIGTERM).
      // You can also call the cleanUp() function directly to handle housekeeping
      // in your own server (e.g., when it is asked to close).
      fn.cleanUp = function (done) {
        fn.watcher.removeAll()
        done()
      }
      Graceful.timeout = 3000
      Graceful.on('SIGINT', fn.cleanUp)
      Graceful.on('SIGTERM', fn.cleanUp)

      // when a file is modifed tell all clients to reload it
      fn.watcher.on('change', function(file) {
        fn.reload(urlsByFile[file])
      })

      // build a RegExp to match all watched file extensions
      var exts = opts.watch || ['html', 'js', 'css']
        , re = new RegExp('\\.(' + exts.join('|') + ')$')

      // pass an `onfile` handler that watches matching files
      opts = Object.create(opts, {
        onfile: { value: function(path, stat) {
          if (!re.test(path)) return
github unboundedsystems / adapt / utils / src / mkdtmp.ts View on Github external
.then((dir) => {
            newDir = dir;
            removeOnExit = graceful.on("exit", remove, true);
            return newDir;
        });
    // tslint:disable-next-line:prefer-object-spread
github unboundedsystems / adapt / testutils / src / docker-mocha.ts View on Github external
onStop(fn: StopFunc) {
        if (!this.removeOnStop) {
            this.removeOnStop = graceful.on("exit", () => this.stop(), true);
        }
        this.stops.push(fn);
    }
}
github mattgodbolt / compiler-explorer / lib / exec.js View on Github external
{env: env, detached: true});
        logger.info(`firejailed pid=${wineServer.pid}`);
    } else {
        logger.info(`Starting a new, long-lived wineserver complex ${server}`);
        wineServer = child_process.spawn(
            wine,
            ["cmd"],
            {env: env, detached: true});
        logger.info(`wineserver pid=${wineServer.pid}`);
    }

    wineServer.on('close', code => {
        logger.info(`WINE server complex exited with code ${code}`);
    });

    Graceful.on('exit', () => {
        const waitingPromises = [];

        function waitForExit(process, name) {
            return new Promise((resolve) => {
                process.on('close', () => {
                    logger.info(`Process '${name}' closed`);
                    resolve();
                });
            });
        }

        if (wineServer && !wineServer.killed) {
            logger.info('Shutting down WINE server complex');
            wineServer.kill();
            if (wineServer.killed) {
                waitingPromises.push(waitForExit(wineServer, "WINE server"));

node-graceful

Graceful process exit manager. allows waiting on multiple async services.

MIT
Latest version published 3 years ago

Package Health Score

45 / 100
Full package analysis

Popular node-graceful functions