Skip to content

open-node/graceful

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@open-node/graceful

Node.js process reload graceful

Build status codecov

Installation

npm i @open-node/graceful --save

Usage

  • your node.js process code
const Graceful = require('@open-node/graceful');

// defined loginfo handle function
const info = console.log

const graceful = Graceful(info);

// get process status, false when existing unless will be true
const status = graceful.enabled()

// regist callback when process exit
graceful.exit(() => {
  // will be called when process exit
});

// wrap function, Once the function is executed, the process will not exit until the function is executed
const wrapped = graceful.runner(willBeWrappedFn);
wrapped(); // Once the function is executed, the process will not exit until the function is executed

// graceful.runnerAsync is the asynchronous version of runner
const wrapped = graceful.runner(willBeWrappedAsyncFn);
await wrapped(); // Once the function is executed, the process will not exit until the function is executed

Table of Contents

Graceful

Parameters

Returns Tick Instance

exit

regist event listenner for exiting

Parameters

Returns void

runner

Wrap the function sync version. Once the be wrapped function is executed, the process will not exit until the function is executed

Parameters

Returns function Be wrapped function

runnerAsync

Wrap the function asynchronous version, Once the be wrapped function is executed, the process will not exit until the function is executed

Parameters

  • fn AsyncFunction will be wrapped fn (asynchronous)

Returns function Be warpped function

enabled

The process status

Returns boolean status