import AbortController from 'abort-controller' ; import { Agent } from 'https' ; import IFetchRequest from "./IFetchRequest" ; /**
* Do the fetch requests.
* It allows a service to implement its own fetch with instrumentation.
*/ export default class FetchRequest implements IFetchRequest { /**
      * Agent instance for connection reuse
      */ private readonly agent : Agent ; /**
     * Create new instance of FetchRequest
     */ constructor ( ) { this . agent = new Agent ( { keepAlive : true } ) ; } param url param callingMethodName param options public async fetch ( url , _callingMethodName , options ) { if ( options ) { options . agent = this . agent ; } else { options = { agent : this . agent } ; } const { timeout = 10000 } = options ; const abortController = new AbortController ( ) ; options . signal = abortController . signal ; const id = setTimeout ( ( ) => { abortController . abort ( ) ; } , timeout ) ; const response = await fetch ( url , options ) ; clearTimeout ( id ) ; return response ; } }