403Webshell
Server IP : 66.29.132.122  /  Your IP : 18.222.20.20
Web Server : LiteSpeed
System : Linux business142.web-hosting.com 4.18.0-553.lve.el8.x86_64 #1 SMP Mon May 27 15:27:34 UTC 2024 x86_64
User : admazpex ( 531)
PHP Version : 7.2.34
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /proc/self/root/proc/thread-self/root/proc/thread-self/root/opt/alt/alt-nodejs19/root/usr/lib/node_modules/npm/lib/utils/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /proc/self/root/proc/thread-self/root/proc/thread-self/root/opt/alt/alt-nodejs19/root/usr/lib/node_modules/npm/lib/utils/timers.js
const EE = require('events')
const fs = require('fs')
const log = require('./log-shim')

// This is an event emiiter but on/off
// only listen on a single internal event that gets
// emitted whenever a timer ends
class Timers extends EE {
  file = null

  #unfinished = new Map()
  #finished = {}
  #onTimeEnd = Symbol('onTimeEnd')
  #initialListener = null
  #initialTimer = null

  constructor ({ listener = null, start = 'npm' } = {}) {
    super()
    this.#initialListener = listener
    this.#initialTimer = start
    this.#init()
  }

  get unfinished () {
    return this.#unfinished
  }

  get finished () {
    return this.#finished
  }

  #init () {
    this.on()
    if (this.#initialListener) {
      this.on(this.#initialListener)
    }
    process.emit('time', this.#initialTimer)
    this.started = this.#unfinished.get(this.#initialTimer)
  }

  on (listener) {
    if (listener) {
      super.on(this.#onTimeEnd, listener)
    } else {
      process.on('time', this.#timeListener)
      process.on('timeEnd', this.#timeEndListener)
    }
  }

  off (listener) {
    if (listener) {
      super.off(this.#onTimeEnd, listener)
    } else {
      this.removeAllListeners(this.#onTimeEnd)
      process.off('time', this.#timeListener)
      process.off('timeEnd', this.#timeEndListener)
    }
  }

  time (name, fn) {
    process.emit('time', name)
    const end = () => process.emit('timeEnd', name)
    if (typeof fn === 'function') {
      const res = fn()
      return res && res.finally ? res.finally(end) : (end(), res)
    }
    return end
  }

  load ({ path } = {}) {
    if (path) {
      this.file = `${path}timing.json`
    }
  }

  writeFile (metadata) {
    if (!this.file) {
      return
    }

    try {
      const globalStart = this.started
      const globalEnd = this.#finished.npm || Date.now()
      const content = {
        metadata,
        timers: this.#finished,
        // add any unfinished timers with their relative start/end
        unfinishedTimers: [...this.#unfinished.entries()].reduce((acc, [name, start]) => {
          acc[name] = [start - globalStart, globalEnd - globalStart]
          return acc
        }, {}),
      }
      fs.writeFileSync(this.file, JSON.stringify(content) + '\n')
    } catch (e) {
      this.file = null
      log.warn('timing', `could not write timing file: ${e}`)
    }
  }

  #timeListener = (name) => {
    this.#unfinished.set(name, Date.now())
  }

  #timeEndListener = (name) => {
    if (this.#unfinished.has(name)) {
      const ms = Date.now() - this.#unfinished.get(name)
      this.#finished[name] = ms
      this.#unfinished.delete(name)
      this.emit(this.#onTimeEnd, name, ms)
    } else {
      log.silly('timing', "Tried to end timer that doesn't exist:", name)
    }
  }
}

module.exports = Timers

Youez - 2016 - github.com/yon3zu
LinuXploit