Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

process: add process.gracefulExit() #6175

Closed
wants to merge 1 commit into from

Commits on Apr 13, 2016

  1. process: add process.gracefulExit()

    Provides a deferrable, async alternative to process.exit(). Whereas
    process.exit() exits the process as quickly as possible,
    process.gracefulExit(), by default, will not exit until the next
    tick of the event loop (scheduled by setImmediate). A callback
    function can be provided to customize the exit process and invoke
    the actual exit when desired or appropriate to do so.
    
    Exits with code `1` on the next tick of the event loop:
    
    ```js
    process.gracefulExit(1);
    ```
    
    Exits with code '0' on `process.nextTick()`:
    
    ```js
    process.gracefulExit(1, (code, exit) => {
      console.log('exiting gracefully on next tick');
      process.nextTick(() => exit(0));
    });
    ```
    
    Immediately exit if the graceful exit is not completed within 10 seconds:
    
    ```js
    process.gracefulExit(0, 10000, (code, exit) => {
      // Wait, do nothing. don't call exit.
    });
    ```
    
    The implementation is such that `process.exit()` is still called, so
    process.on('exit') handlers will be invoked.
    
    In cluster/child-processes with IPC, this does *not* take the place
    of process.disconnect().
    jasnell committed Apr 13, 2016
    Configuration menu
    Copy the full SHA
    4a4e15a View commit details
    Browse the repository at this point in the history