export interface InterceptorResolved < T = any > { ( value ) : T | Promise < T > ; } export interface InterceptorRejected { ( error ) : any | Promise < any > ; } export interface Interceptor < T = any > { resolved : InterceptorResolved < T > ; rejected ? : InterceptorRejected ; } export interface InterceptorExecutor { ( interceptor ) : void ; } export default class InterceptorManager < T = any > { private id = 0 ; private interceptors : AnyObject < Interceptor < T > > = { } ; public use ( resolved , rejected ? ) { this . interceptors [ ++ this . id ] = { resolved , rejected , } ; return this . id ; } public eject ( id ) { delete this . interceptors [ id ] ; } public forEach ( executor , reverse ? ) { let interceptors = Object . keys ( this . interceptors ) . map ( ( id ) => this . interceptors [ id ] ) ; if ( reverse === 'reverse' ) { interceptors = interceptors . reverse ( ) ; } interceptors . forEach ( executor ) ; } }