import { Lazy } from 'fp-ts/lib/function' ; import { IORef } from 'fp-ts/lib/IORef' ; import { Reader } from 'fp-ts/lib/Reader' ; import { State } from 'fp-ts/lib/State' ; import { TaskEither } from 'fp-ts/lib/TaskEither' ; export interface export interface BreakerOptions { type { number } memberof maxBreakerFailures : number ; type { number } memberof resetTimeoutSecs : number ; type { string } memberof breakerDescription : string ; } export class export class BreakerClosed { public readonly tag = 'Closed' ; constructor ( public readonly errorCount ) { } } export class export class BreakerOpen { public readonly tag = 'Open' ; constructor ( public readonly openEndTime ) { } } export type BreakerState export type BreakerState = BreakerClosed | BreakerOpen ; export interface template T export interface BreakerEnvironment < T > { request : Lazy < Promise < T > > ; breakerState : IORef < BreakerState > ; } /**
 * Circuit breaker generator type.
 * It takes options required to instantiate a breaker and returns a State monad of result.
 */ export type CircuitBreaker < T > = Reader < BreakerOptions , State < BreakerEnvironment < T > , TaskEither < Error , T > > > ;