license export interface TeenyStatisticsOptions { /**
     * A positive number representing when to issue a warning about the number
     * of concurrent requests using teeny-request.
     * Set to 0 to disable this warning.
     * Corresponds to the TEENY_REQUEST_WARN_CONCURRENT_REQUESTS environment
     * variable.
     */ concurrentRequests ? : number ; } type TeenyStatisticsConfig = Required < TeenyStatisticsOptions > ; /**
 * TeenyStatisticsCounters is distinct from TeenyStatisticsOptions:
 * Used when dumping current counters and other internal metrics.
 */ export interface TeenyStatisticsCounters { concurrentRequests : number ; } class extends Error description see process . emitWarning export class TeenyStatisticsWarning extends Error { static readonly CONCURRENT_REQUESTS = 'ConcurrentRequestsExceededWarning' ; public threshold = 0 ; public type = '' ; public value = 0 ; param { string } message constructor ( message ) { super ( message ) ; this . name = this . constructor . name ; Error . captureStackTrace ( this , this . constructor ) ; } } class description export class TeenyStatistics { description type { number } static readonly default static readonly DEFAULT_WARN_CONCURRENT_REQUESTS = 5000 ; type { TeenyStatisticsConfig } private private _options : TeenyStatisticsConfig ; type { number } private default private _concurrentRequests = 0 ; type { boolean } private default private _didConcurrentRequestWarn = false ; param { TeenyStatisticsOptions } opts constructor ( opts ? ) { this . _options = TeenyStatistics . _prepareOptions ( opts ) ; } return { TeenyStatisticsOptions } getOptions ( ) { return Object . assign ( { } , this . _options ) ; } param { TeenyStatisticsOptions } opts returns { TeenyStatisticsConfig } see _prepareOptions setOptions ( opts ? ) { const oldOpts = this . _options ; this . _options = TeenyStatistics . _prepareOptions ( opts ) ; return oldOpts ; } readonly return { TeenyStatisticsCounters } get counters ( ) : TeenyStatisticsCounters { return { concurrentRequests : this . _concurrentRequests , } ; } description requestStarting ( ) { this . _concurrentRequests ++ ; if ( this . _options . concurrentRequests > 0 && this . _concurrentRequests >= this . _options . concurrentRequests && ! this . _didConcurrentRequestWarn ) { this . _didConcurrentRequestWarn = true ; const warning = new TeenyStatisticsWarning ( 'Possible excessive concurrent requests detected. ' + this . _concurrentRequests + ' requests in-flight, which exceeds the configured threshold of ' + this . _options . concurrentRequests + '. Use the TEENY_REQUEST_WARN_CONCURRENT_REQUESTS environment ' + 'variable or the concurrentRequests option of teeny-request to ' + 'increase or disable (0) this warning.' ) ; warning . type = TeenyStatisticsWarning . CONCURRENT_REQUESTS ; warning . value = this . _concurrentRequests ; warning . threshold = this . _options . concurrentRequests ; process . emitWarning ( warning ) ; } } description requestFinished ( ) { this . _concurrentRequests -- ; } param { TeenyStatisticsOptions } opts returns { TeenyStatisticsOptions } private private static _prepareOptions ( { concurrentRequests : diConcurrentRequests , } = { } ) { let concurrentRequests = this . DEFAULT_WARN_CONCURRENT_REQUESTS ; const envConcurrentRequests = Number ( process . env . TEENY_REQUEST_WARN_CONCURRENT_REQUESTS ) ; if ( diConcurrentRequests !== undefined ) { concurrentRequests = diConcurrentRequests ; } else if ( ! Number . isNaN ( envConcurrentRequests ) ) { concurrentRequests = envConcurrentRequests ; } return { concurrentRequests } ; } }