New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

shutdown-emitter

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

shutdown-emitter

Node.JS Shutdown Event Emitter

latest
Source
npmnpm
Version
1.1.9
Version published
Maintainers
1
Created
Source

Node.JS Shutdown Emitter

Handling graceful application services shutdown.

Install

npm i shutdown-emitter

Usage

Promisified Service

Handle graceful shutdown for service with promisified connection and disconnection methods.

import { ShutdownEmitter, ShutdownPromiseListener } from "./src";

declare const abstractService: {
    connect(): Promise<void>;
    disconnect(): Promise<void>;
};
declare const shutdownEmitter: ShutdownEmitter;

abstractService
    .connect()
    .then(() => {
        const shutdownListener = ShutdownPromiseListener(abstractService.connect);
        shutdownEmitter.addListener(shutdownListener);
    });

Callback Service

Handle graceful shutdown for service with callback-based connection and disconnection methods.

import express from "express";
import { ShutdownEmitter, ShutdownCallbackListener } from "./src";

declare const abstractService: {
    connect(cb: () => void): void;
    disconnect(cb: (err?: Error) => void): void;
};
declare const shutdownEmitter: ShutdownEmitter;

abstractService.connect(() => {
    const shutdownListener = ShutdownCallbackListener(abstractService.disconnect);
    shutdownListener.addListener(shutdownListener);
});

Redis Connection

import { RedisClient } from "redis";
import { ShutdownEmitter, ShutdownCallbackListener } from "./src";

declare const redis: RedisClient;
declare const shutdownEmitter: ShutdownEmitter;

shutdownEmitter.addListener(ShutdownCallbackListener(redis.quit));

Express Application

import express from "express";
import { ShutdownEmitter, ShutdownCallbackListener } from "./src";

declare const app: express.Application;
declare const shutdownEmitter: ShutdownEmitter;

const server = app.listen(() => shutdownEmitter.addListener(ShutdownCallbackListener(server.close)));

Keywords

nodejs

FAQs

Package last updated on 08 Oct 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts