HEX
Server: Apache
System: Linux b5.s-host.com.ua 4.18.0-305.10.2.el7.x86_64 #1 SMP Fri Jul 23 21:00:55 UTC 2021 x86_64
User: unelbhzm (1470)
PHP: 8.0.18
Disabled: NONE
Upload Files
File: //home/unelbhzm/usr/lib/node_modules/npm/node_modules/@npmcli/arborist/bin/lib/timers.js
const { bin: options } = require('./options.js')
const log = require('./logging.js')

const timers = new Map()
const finished = new Map()

process.on('time', name => {
  if (timers.has(name)) {
    throw new Error('conflicting timer! ' + name)
  }
  timers.set(name, process.hrtime.bigint())
})

process.on('timeEnd', name => {
  if (!timers.has(name)) {
    throw new Error('timer not started! ' + name)
  }
  const elapsed = Number(process.hrtime.bigint() - timers.get(name))
  timers.delete(name)
  finished.set(name, elapsed)
  if (options.timing) {
    log.info('timeEnd', `${name} ${elapsed / 1e9}s`, log.meta({ force: options.timing === 'always' }))
  }
})

process.on('exit', () => {
  for (const name of timers.keys()) {
    log.error('timeError', 'Dangling timer:', name)
    process.exitCode = 1
  }
})

module.exports = finished