1.1.9 • Published 5 years ago

shutdown-emitter v1.1.9

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

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)));
1.1.9

5 years ago

1.1.8

5 years ago

1.1.7

5 years ago

1.1.6

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago