TopGit theo dõi mcollina/close-with-grace trên GitHub, đã đạt 304 sao. Exit your process, gracefully (if possible) - for Node.js
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
Exit your process, gracefully (if possible) - for Node.js
Install
npm i close-with-grace
Usage
const closeWithGrace = require('close-with-grace')
// delay is the number of milliseconds for the graceful close to
// finish.
closeWithGrace({ delay: 500 }, async function ({ signal, err, manual }) {
if (err) {
console.error(err)
}
await closeYourServer()
})
// default delay is 10000
// to disable delay feature at all, pass falsy value to delay option.
closeWithGrace({ delay: false }, () => await somethingUseful())
Injecting custom logger
const closeWithGrace = require('close-with-grace')
// delay is the number of milliseconds for the graceful close to
// finish.
closeWithGrace(
{
delay: 500,
logger: { error: (m) => console.error(`[close-with-grace] ${m}`) }
},
async function ({ signal, err, manual }) {
if (err) {
console.error(err)
}
await closeYourServer()
})
// default logger is console
// to disable logging at all, pass falsy value to logger option.
closeWithGrace({ logger: false }, () => await somethingUseful())
Example with Fastify
import fastify from 'fastify'
import closeWithGrace from 'close-with-grace'
const app = fastify()
closeWithGrace(async function ({ signal, err, manual }) {
if (err) {
app.log.error({ err }, 'server closing with error')
} else {
app.log.info(`${signal} received, server closing`)
}
await app.close()
})
await app.listen()
Skipping specific events
Skip specific events from triggering the graceful close. Note: You are responsible for handling skipped events yourself.
Note: You must handle skipped events yourself, otherwise they may cause the process to crash or exit unexpectedly.
onSecondError(error): A callback to execute if the process throws an uncaughtException
or an unhandledRejection while fn is executing.
onSecondSignal(signal): A callback to execute if the process receives another
signal while fn is executing.
onTimeout(delay): A callback to execute if fn failed to completed after delay milliseconds.
Both onSecondError, onSecondSignal or onTimeout can be used to perform custom logic, but process.exit(1)
will be immediately be invoked after they exit so no asynchronous operations are possible.
fn({ err, signal, manual } [, cb])
Execute the given function to perform a graceful close.
The function can either return a Promise or call the callback.
If this function does not error, the process will be closed with
exit code 0.
If the function rejects with an Error, or call the callback with an
Error as first argument, the process will be closed with exit code
1.
return values
Calling closeWithGrace() will return an object as formed:
close(): close the process, the manual argument will be set to
true.
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/mcollina/close-with-grace là nguồn chính thức.
mcollina/close-with-grace có phải mã nguồn mở không?
Có — mcollina/close-with-grace phát hành theo license MIT, nghĩa là mã nguồn mở để đọc, fork và (tùy license) tái sử dụng. Mã: github.com/mcollina/close-with-grace.
mcollina/close-with-grace có website riêng không?
TopGit chưa ghi nhận URL trang chủ cho mcollina/close-with-grace. Phần README ở tab phía trên thường có link demo, hoặc xem mô tả GitHub của repo.
mcollina/close-with-grace dùng license gì?
mcollina/close-with-grace phát hành theo license MIT. Nên mở file LICENSE trên GitHub để xác nhận — license metadata đôi khi lệch với thực tế dự án.
mcollina/close-with-grace là gì?
mcollina/close-with-grace (mcollina/close-with-grace) là dự án JavaScript trên GitHub. Theo mô tả gốc: Exit your process, gracefully (if possible) - for Node.js
Đọc đầy đủ README ở tab phía trên.
Chưa chắc close-with-grace có hợp với bạn?
Để ChatGPT, Claude hoặc Perplexity tìm hiểu giúp — bấm bên dưới và xem AI nói gì về close-with-grace.