Added typings for sticky-cluster

This commit is contained in:
Austin Turner
2017-11-25 21:22:33 -07:00
parent 3289762cca
commit 57a67f6f8f
4 changed files with 83 additions and 0 deletions

25
types/sticky-cluster/index.d.ts vendored Normal file
View File

@@ -0,0 +1,25 @@
// Type definitions for sticky-cluster 0.3
// Project: https://github.com/uqee/sticky-cluster
// Definitions by: Austin Turner <https://github.com/paustint>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
/// <reference types="node"/>
import * as http from 'http';
declare namespace stickyCluster {
type InitializeFn = (callback: Callback) => void;
type Callback = (server: http.Server) => void;
interface Options {
concurrency?: number;
port?: number;
debug?: boolean;
prefix?: string;
env?: (index: number) => { stickycluster_worker_index: number };
hardShutdownDelay?: number;
errorHandler?: (err: any) => void;
}
}
declare function stickyCluster(callback: stickyCluster.InitializeFn, options?: stickyCluster.Options): void;
export = stickyCluster;

View File

@@ -0,0 +1,34 @@
import stickyCluster = require('sticky-cluster');
import * as express from 'express';
import * as http from 'http';
/** test with all params */
stickyCluster(
(callback) => {
const app = express();
const server = http.createServer(app);
// don't do server.listen(), just pass the server instance into the callback
callback(server);
},
{
prefix: 'sticky-cluster:',
concurrency: 10,
port: 3000,
debug: true,
hardShutdownDelay: 60 * 1000,
env: (index) => ({ stickycluster_worker_index: index }),
errorHandler: (err) => { console.log(err); process.exit(1); }
}
);
/** test with no params */
stickyCluster(
(callback) => {
const app = express();
const server = http.createServer(app);
// don't do server.listen(), just pass the server instance into the callback
callback(server);
}
);

View File

@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"sticky-cluster-tests.ts"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }