diff --git a/types/opossum/index.d.ts b/types/opossum/index.d.ts index b955f940e3..e79a9c4bba 100644 --- a/types/opossum/index.d.ts +++ b/types/opossum/index.d.ts @@ -1,23 +1,26 @@ // Type definitions for opossum 1.9 // Project: https://github.com/nodeshift/opossum // Definitions by: Quinn Langille +// Willy Zhang // Lance Ball // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 /// import * as stream from "stream"; +import { EventEmitter } from "events"; -export type Action = () => any; +export type Action = (...args: any[]) => any; -export class CircuitBreaker { +export class CircuitBreaker extends EventEmitter { clearCache(): void; close(): void; disable(): void; enable(): void; - fallback(): CircuitBreaker; - fire(): Promise; - healthCheck(func: () => Promise, interval: number): Promise; + fallback(func?: (...args: any[]) => any): this; + fire(...args: any[]): Promise; + healthCheck(func: (...args: any[]) => Promise, interval?: number): Promise; + on(event: string | symbol, listener: (...args: any[]) => void): this; open(): void; promisify(action: Action): Promise; stats(): stream.Transform; @@ -35,6 +38,22 @@ export class CircuitBreaker { static readonly volumeThreshold: symbol; } +export enum Event { + cacheHit = 'cacheHit', + cacheMiss = 'cacheMiss', + close = 'close', + failure = 'failure', + fallback = 'fallback', + fire = 'fire', + halfOpen = 'halfOpen', + healthCheckFailed = 'health-check-failed', + open = 'open', + reject = 'reject', + semaphoreLocked = 'semaphore-locked', + success = 'success', + timeout = 'timeout' +} + export interface CircuitBreakerOptions { timeout?: number; maxFailures?: number;