[6a3a178] | 1 | declare module 'cluster' {
|
---|
| 2 | import * as child from 'child_process';
|
---|
| 3 | import EventEmitter = require('events');
|
---|
| 4 | import * as net from 'net';
|
---|
| 5 |
|
---|
| 6 | // interfaces
|
---|
| 7 | interface ClusterSettings {
|
---|
| 8 | execArgv?: string[] | undefined; // default: process.execArgv
|
---|
| 9 | exec?: string | undefined;
|
---|
| 10 | args?: string[] | undefined;
|
---|
| 11 | silent?: boolean | undefined;
|
---|
| 12 | stdio?: any[] | undefined;
|
---|
| 13 | uid?: number | undefined;
|
---|
| 14 | gid?: number | undefined;
|
---|
| 15 | inspectPort?: number | (() => number) | undefined;
|
---|
| 16 | }
|
---|
| 17 |
|
---|
| 18 | interface Address {
|
---|
| 19 | address: string;
|
---|
| 20 | port: number;
|
---|
| 21 | addressType: number | "udp4" | "udp6"; // 4, 6, -1, "udp4", "udp6"
|
---|
| 22 | }
|
---|
| 23 |
|
---|
| 24 | class Worker extends EventEmitter {
|
---|
| 25 | id: number;
|
---|
| 26 | process: child.ChildProcess;
|
---|
| 27 | send(message: any, sendHandle?: any, callback?: (error: Error | null) => void): boolean;
|
---|
| 28 | kill(signal?: string): void;
|
---|
| 29 | destroy(signal?: string): void;
|
---|
| 30 | disconnect(): void;
|
---|
| 31 | isConnected(): boolean;
|
---|
| 32 | isDead(): boolean;
|
---|
| 33 | exitedAfterDisconnect: boolean;
|
---|
| 34 |
|
---|
| 35 | /**
|
---|
| 36 | * events.EventEmitter
|
---|
| 37 | * 1. disconnect
|
---|
| 38 | * 2. error
|
---|
| 39 | * 3. exit
|
---|
| 40 | * 4. listening
|
---|
| 41 | * 5. message
|
---|
| 42 | * 6. online
|
---|
| 43 | */
|
---|
| 44 | addListener(event: string, listener: (...args: any[]) => void): this;
|
---|
| 45 | addListener(event: "disconnect", listener: () => void): this;
|
---|
| 46 | addListener(event: "error", listener: (error: Error) => void): this;
|
---|
| 47 | addListener(event: "exit", listener: (code: number, signal: string) => void): this;
|
---|
| 48 | addListener(event: "listening", listener: (address: Address) => void): this;
|
---|
| 49 | addListener(event: "message", listener: (message: any, handle: net.Socket | net.Server) => void): this; // the handle is a net.Socket or net.Server object, or undefined.
|
---|
| 50 | addListener(event: "online", listener: () => void): this;
|
---|
| 51 |
|
---|
| 52 | emit(event: string | symbol, ...args: any[]): boolean;
|
---|
| 53 | emit(event: "disconnect"): boolean;
|
---|
| 54 | emit(event: "error", error: Error): boolean;
|
---|
| 55 | emit(event: "exit", code: number, signal: string): boolean;
|
---|
| 56 | emit(event: "listening", address: Address): boolean;
|
---|
| 57 | emit(event: "message", message: any, handle: net.Socket | net.Server): boolean;
|
---|
| 58 | emit(event: "online"): boolean;
|
---|
| 59 |
|
---|
| 60 | on(event: string, listener: (...args: any[]) => void): this;
|
---|
| 61 | on(event: "disconnect", listener: () => void): this;
|
---|
| 62 | on(event: "error", listener: (error: Error) => void): this;
|
---|
| 63 | on(event: "exit", listener: (code: number, signal: string) => void): this;
|
---|
| 64 | on(event: "listening", listener: (address: Address) => void): this;
|
---|
| 65 | on(event: "message", listener: (message: any, handle: net.Socket | net.Server) => void): this; // the handle is a net.Socket or net.Server object, or undefined.
|
---|
| 66 | on(event: "online", listener: () => void): this;
|
---|
| 67 |
|
---|
| 68 | once(event: string, listener: (...args: any[]) => void): this;
|
---|
| 69 | once(event: "disconnect", listener: () => void): this;
|
---|
| 70 | once(event: "error", listener: (error: Error) => void): this;
|
---|
| 71 | once(event: "exit", listener: (code: number, signal: string) => void): this;
|
---|
| 72 | once(event: "listening", listener: (address: Address) => void): this;
|
---|
| 73 | once(event: "message", listener: (message: any, handle: net.Socket | net.Server) => void): this; // the handle is a net.Socket or net.Server object, or undefined.
|
---|
| 74 | once(event: "online", listener: () => void): this;
|
---|
| 75 |
|
---|
| 76 | prependListener(event: string, listener: (...args: any[]) => void): this;
|
---|
| 77 | prependListener(event: "disconnect", listener: () => void): this;
|
---|
| 78 | prependListener(event: "error", listener: (error: Error) => void): this;
|
---|
| 79 | prependListener(event: "exit", listener: (code: number, signal: string) => void): this;
|
---|
| 80 | prependListener(event: "listening", listener: (address: Address) => void): this;
|
---|
| 81 | prependListener(event: "message", listener: (message: any, handle: net.Socket | net.Server) => void): this; // the handle is a net.Socket or net.Server object, or undefined.
|
---|
| 82 | prependListener(event: "online", listener: () => void): this;
|
---|
| 83 |
|
---|
| 84 | prependOnceListener(event: string, listener: (...args: any[]) => void): this;
|
---|
| 85 | prependOnceListener(event: "disconnect", listener: () => void): this;
|
---|
| 86 | prependOnceListener(event: "error", listener: (error: Error) => void): this;
|
---|
| 87 | prependOnceListener(event: "exit", listener: (code: number, signal: string) => void): this;
|
---|
| 88 | prependOnceListener(event: "listening", listener: (address: Address) => void): this;
|
---|
| 89 | prependOnceListener(event: "message", listener: (message: any, handle: net.Socket | net.Server) => void): this; // the handle is a net.Socket or net.Server object, or undefined.
|
---|
| 90 | prependOnceListener(event: "online", listener: () => void): this;
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | interface Cluster extends EventEmitter {
|
---|
| 94 | Worker: Worker;
|
---|
| 95 | disconnect(callback?: () => void): void;
|
---|
| 96 | fork(env?: any): Worker;
|
---|
| 97 | isMaster: boolean;
|
---|
| 98 | isWorker: boolean;
|
---|
| 99 | // TODO: cluster.schedulingPolicy
|
---|
| 100 | settings: ClusterSettings;
|
---|
| 101 | setupMaster(settings?: ClusterSettings): void;
|
---|
| 102 | worker?: Worker | undefined;
|
---|
| 103 | workers?: {
|
---|
| 104 | [index: string]: Worker | undefined
|
---|
| 105 | } | undefined;
|
---|
| 106 |
|
---|
| 107 | /**
|
---|
| 108 | * events.EventEmitter
|
---|
| 109 | * 1. disconnect
|
---|
| 110 | * 2. exit
|
---|
| 111 | * 3. fork
|
---|
| 112 | * 4. listening
|
---|
| 113 | * 5. message
|
---|
| 114 | * 6. online
|
---|
| 115 | * 7. setup
|
---|
| 116 | */
|
---|
| 117 | addListener(event: string, listener: (...args: any[]) => void): this;
|
---|
| 118 | addListener(event: "disconnect", listener: (worker: Worker) => void): this;
|
---|
| 119 | addListener(event: "exit", listener: (worker: Worker, code: number, signal: string) => void): this;
|
---|
| 120 | addListener(event: "fork", listener: (worker: Worker) => void): this;
|
---|
| 121 | addListener(event: "listening", listener: (worker: Worker, address: Address) => void): this;
|
---|
| 122 | addListener(event: "message", listener: (worker: Worker, message: any, handle: net.Socket | net.Server) => void): this; // the handle is a net.Socket or net.Server object, or undefined.
|
---|
| 123 | addListener(event: "online", listener: (worker: Worker) => void): this;
|
---|
| 124 | addListener(event: "setup", listener: (settings: ClusterSettings) => void): this;
|
---|
| 125 |
|
---|
| 126 | emit(event: string | symbol, ...args: any[]): boolean;
|
---|
| 127 | emit(event: "disconnect", worker: Worker): boolean;
|
---|
| 128 | emit(event: "exit", worker: Worker, code: number, signal: string): boolean;
|
---|
| 129 | emit(event: "fork", worker: Worker): boolean;
|
---|
| 130 | emit(event: "listening", worker: Worker, address: Address): boolean;
|
---|
| 131 | emit(event: "message", worker: Worker, message: any, handle: net.Socket | net.Server): boolean;
|
---|
| 132 | emit(event: "online", worker: Worker): boolean;
|
---|
| 133 | emit(event: "setup", settings: ClusterSettings): boolean;
|
---|
| 134 |
|
---|
| 135 | on(event: string, listener: (...args: any[]) => void): this;
|
---|
| 136 | on(event: "disconnect", listener: (worker: Worker) => void): this;
|
---|
| 137 | on(event: "exit", listener: (worker: Worker, code: number, signal: string) => void): this;
|
---|
| 138 | on(event: "fork", listener: (worker: Worker) => void): this;
|
---|
| 139 | on(event: "listening", listener: (worker: Worker, address: Address) => void): this;
|
---|
| 140 | on(event: "message", listener: (worker: Worker, message: any, handle: net.Socket | net.Server) => void): this; // the handle is a net.Socket or net.Server object, or undefined.
|
---|
| 141 | on(event: "online", listener: (worker: Worker) => void): this;
|
---|
| 142 | on(event: "setup", listener: (settings: ClusterSettings) => void): this;
|
---|
| 143 |
|
---|
| 144 | once(event: string, listener: (...args: any[]) => void): this;
|
---|
| 145 | once(event: "disconnect", listener: (worker: Worker) => void): this;
|
---|
| 146 | once(event: "exit", listener: (worker: Worker, code: number, signal: string) => void): this;
|
---|
| 147 | once(event: "fork", listener: (worker: Worker) => void): this;
|
---|
| 148 | once(event: "listening", listener: (worker: Worker, address: Address) => void): this;
|
---|
| 149 | once(event: "message", listener: (worker: Worker, message: any, handle: net.Socket | net.Server) => void): this; // the handle is a net.Socket or net.Server object, or undefined.
|
---|
| 150 | once(event: "online", listener: (worker: Worker) => void): this;
|
---|
| 151 | once(event: "setup", listener: (settings: ClusterSettings) => void): this;
|
---|
| 152 |
|
---|
| 153 | prependListener(event: string, listener: (...args: any[]) => void): this;
|
---|
| 154 | prependListener(event: "disconnect", listener: (worker: Worker) => void): this;
|
---|
| 155 | prependListener(event: "exit", listener: (worker: Worker, code: number, signal: string) => void): this;
|
---|
| 156 | prependListener(event: "fork", listener: (worker: Worker) => void): this;
|
---|
| 157 | prependListener(event: "listening", listener: (worker: Worker, address: Address) => void): this;
|
---|
| 158 | prependListener(event: "message", listener: (worker: Worker, message: any, handle: net.Socket | net.Server) => void): this; // the handle is a net.Socket or net.Server object, or undefined.
|
---|
| 159 | prependListener(event: "online", listener: (worker: Worker) => void): this;
|
---|
| 160 | prependListener(event: "setup", listener: (settings: ClusterSettings) => void): this;
|
---|
| 161 |
|
---|
| 162 | prependOnceListener(event: string, listener: (...args: any[]) => void): this;
|
---|
| 163 | prependOnceListener(event: "disconnect", listener: (worker: Worker) => void): this;
|
---|
| 164 | prependOnceListener(event: "exit", listener: (worker: Worker, code: number, signal: string) => void): this;
|
---|
| 165 | prependOnceListener(event: "fork", listener: (worker: Worker) => void): this;
|
---|
| 166 | prependOnceListener(event: "listening", listener: (worker: Worker, address: Address) => void): this;
|
---|
| 167 | // the handle is a net.Socket or net.Server object, or undefined.
|
---|
| 168 | prependOnceListener(event: "message", listener: (worker: Worker, message: any, handle: net.Socket | net.Server) => void): this;
|
---|
| 169 | prependOnceListener(event: "online", listener: (worker: Worker) => void): this;
|
---|
| 170 | prependOnceListener(event: "setup", listener: (settings: ClusterSettings) => void): this;
|
---|
| 171 | }
|
---|
| 172 |
|
---|
| 173 | function disconnect(callback?: () => void): void;
|
---|
| 174 | function fork(env?: any): Worker;
|
---|
| 175 | const isMaster: boolean;
|
---|
| 176 | const isWorker: boolean;
|
---|
| 177 | // TODO: cluster.schedulingPolicy
|
---|
| 178 | const settings: ClusterSettings;
|
---|
| 179 | function setupMaster(settings?: ClusterSettings): void;
|
---|
| 180 | const worker: Worker;
|
---|
| 181 | const workers: {
|
---|
| 182 | [index: string]: Worker | undefined
|
---|
| 183 | };
|
---|
| 184 |
|
---|
| 185 | /**
|
---|
| 186 | * events.EventEmitter
|
---|
| 187 | * 1. disconnect
|
---|
| 188 | * 2. exit
|
---|
| 189 | * 3. fork
|
---|
| 190 | * 4. listening
|
---|
| 191 | * 5. message
|
---|
| 192 | * 6. online
|
---|
| 193 | * 7. setup
|
---|
| 194 | */
|
---|
| 195 | function addListener(event: string, listener: (...args: any[]) => void): Cluster;
|
---|
| 196 | function addListener(event: "disconnect", listener: (worker: Worker) => void): Cluster;
|
---|
| 197 | function addListener(event: "exit", listener: (worker: Worker, code: number, signal: string) => void): Cluster;
|
---|
| 198 | function addListener(event: "fork", listener: (worker: Worker) => void): Cluster;
|
---|
| 199 | function addListener(event: "listening", listener: (worker: Worker, address: Address) => void): Cluster;
|
---|
| 200 | // the handle is a net.Socket or net.Server object, or undefined.
|
---|
| 201 | function addListener(event: "message", listener: (worker: Worker, message: any, handle: net.Socket | net.Server) => void): Cluster;
|
---|
| 202 | function addListener(event: "online", listener: (worker: Worker) => void): Cluster;
|
---|
| 203 | function addListener(event: "setup", listener: (settings: ClusterSettings) => void): Cluster;
|
---|
| 204 |
|
---|
| 205 | function emit(event: string | symbol, ...args: any[]): boolean;
|
---|
| 206 | function emit(event: "disconnect", worker: Worker): boolean;
|
---|
| 207 | function emit(event: "exit", worker: Worker, code: number, signal: string): boolean;
|
---|
| 208 | function emit(event: "fork", worker: Worker): boolean;
|
---|
| 209 | function emit(event: "listening", worker: Worker, address: Address): boolean;
|
---|
| 210 | function emit(event: "message", worker: Worker, message: any, handle: net.Socket | net.Server): boolean;
|
---|
| 211 | function emit(event: "online", worker: Worker): boolean;
|
---|
| 212 | function emit(event: "setup", settings: ClusterSettings): boolean;
|
---|
| 213 |
|
---|
| 214 | function on(event: string, listener: (...args: any[]) => void): Cluster;
|
---|
| 215 | function on(event: "disconnect", listener: (worker: Worker) => void): Cluster;
|
---|
| 216 | function on(event: "exit", listener: (worker: Worker, code: number, signal: string) => void): Cluster;
|
---|
| 217 | function on(event: "fork", listener: (worker: Worker) => void): Cluster;
|
---|
| 218 | function on(event: "listening", listener: (worker: Worker, address: Address) => void): Cluster;
|
---|
| 219 | function on(event: "message", listener: (worker: Worker, message: any, handle: net.Socket | net.Server) => void): Cluster; // the handle is a net.Socket or net.Server object, or undefined.
|
---|
| 220 | function on(event: "online", listener: (worker: Worker) => void): Cluster;
|
---|
| 221 | function on(event: "setup", listener: (settings: ClusterSettings) => void): Cluster;
|
---|
| 222 |
|
---|
| 223 | function once(event: string, listener: (...args: any[]) => void): Cluster;
|
---|
| 224 | function once(event: "disconnect", listener: (worker: Worker) => void): Cluster;
|
---|
| 225 | function once(event: "exit", listener: (worker: Worker, code: number, signal: string) => void): Cluster;
|
---|
| 226 | function once(event: "fork", listener: (worker: Worker) => void): Cluster;
|
---|
| 227 | function once(event: "listening", listener: (worker: Worker, address: Address) => void): Cluster;
|
---|
| 228 | function once(event: "message", listener: (worker: Worker, message: any, handle: net.Socket | net.Server) => void): Cluster; // the handle is a net.Socket or net.Server object, or undefined.
|
---|
| 229 | function once(event: "online", listener: (worker: Worker) => void): Cluster;
|
---|
| 230 | function once(event: "setup", listener: (settings: ClusterSettings) => void): Cluster;
|
---|
| 231 |
|
---|
| 232 | function removeListener(event: string, listener: (...args: any[]) => void): Cluster;
|
---|
| 233 | function removeAllListeners(event?: string): Cluster;
|
---|
| 234 | function setMaxListeners(n: number): Cluster;
|
---|
| 235 | function getMaxListeners(): number;
|
---|
| 236 | function listeners(event: string): Function[];
|
---|
| 237 | function listenerCount(type: string): number;
|
---|
| 238 |
|
---|
| 239 | function prependListener(event: string, listener: (...args: any[]) => void): Cluster;
|
---|
| 240 | function prependListener(event: "disconnect", listener: (worker: Worker) => void): Cluster;
|
---|
| 241 | function prependListener(event: "exit", listener: (worker: Worker, code: number, signal: string) => void): Cluster;
|
---|
| 242 | function prependListener(event: "fork", listener: (worker: Worker) => void): Cluster;
|
---|
| 243 | function prependListener(event: "listening", listener: (worker: Worker, address: Address) => void): Cluster;
|
---|
| 244 | // the handle is a net.Socket or net.Server object, or undefined.
|
---|
| 245 | function prependListener(event: "message", listener: (worker: Worker, message: any, handle: net.Socket | net.Server) => void): Cluster;
|
---|
| 246 | function prependListener(event: "online", listener: (worker: Worker) => void): Cluster;
|
---|
| 247 | function prependListener(event: "setup", listener: (settings: ClusterSettings) => void): Cluster;
|
---|
| 248 |
|
---|
| 249 | function prependOnceListener(event: string, listener: (...args: any[]) => void): Cluster;
|
---|
| 250 | function prependOnceListener(event: "disconnect", listener: (worker: Worker) => void): Cluster;
|
---|
| 251 | function prependOnceListener(event: "exit", listener: (worker: Worker, code: number, signal: string) => void): Cluster;
|
---|
| 252 | function prependOnceListener(event: "fork", listener: (worker: Worker) => void): Cluster;
|
---|
| 253 | function prependOnceListener(event: "listening", listener: (worker: Worker, address: Address) => void): Cluster;
|
---|
| 254 | // the handle is a net.Socket or net.Server object, or undefined.
|
---|
| 255 | function prependOnceListener(event: "message", listener: (worker: Worker, message: any, handle: net.Socket | net.Server) => void): Cluster;
|
---|
| 256 | function prependOnceListener(event: "online", listener: (worker: Worker) => void): Cluster;
|
---|
| 257 | function prependOnceListener(event: "setup", listener: (settings: ClusterSettings) => void): Cluster;
|
---|
| 258 |
|
---|
| 259 | function eventNames(): string[];
|
---|
| 260 | }
|
---|