$26 GRAYBYTE WORDPRESS FILE MANAGER $48

SERVER : vnpttt-amd7f72-h1.vietnix.vn #1 SMP Fri May 24 12:42:50 UTC 2024
SERVER IP : 103.200.23.149 | ADMIN IP 216.73.216.22
OPTIONS : CRL = ON | WGT = ON | SDO = OFF | PKEX = OFF
DEACTIVATED : NONE

/opt/alt/alt-nodejs19/root/usr/lib/node_modules/npm/lib/utils/

HOME
Current File : /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

Current_dir [ NOT WRITEABLE ] Document_root [ WRITEABLE ]


[ Back ]
NAME
SIZE
LAST TOUCH
USER
CAN-I?
FUNCTIONS
..
--
31 Aug 2024 8.02 AM
root / root
0755
completion
--
31 Aug 2024 8.02 AM
root / root
0755
config
--
31 Aug 2024 8.02 AM
root / root
0755
ansi-trim.js
0.169 KB
7 Dec 2023 1.07 AM
root / root
0644
audit-error.js
1.016 KB
7 Dec 2023 1.07 AM
root / root
0644
auth.js
2.804 KB
7 Dec 2023 1.07 AM
root / root
0644
cmd-list.js
2.163 KB
7 Dec 2023 1.07 AM
root / root
0644
completion.fish
1.559 KB
7 Dec 2023 1.07 AM
root / root
0644
completion.sh
1.854 KB
7 Dec 2023 1.07 AM
root / root
0755
did-you-mean.js
1.463 KB
7 Dec 2023 1.07 AM
root / root
0644
display.js
3.434 KB
7 Dec 2023 1.07 AM
root / root
0644
error-message.js
13.532 KB
7 Dec 2023 1.07 AM
root / root
0644
exit-handler.js
6.739 KB
7 Dec 2023 1.07 AM
root / root
0644
explain-dep.js
3.5 KB
7 Dec 2023 1.07 AM
root / root
0644
explain-eresolve.js
2.546 KB
7 Dec 2023 1.07 AM
root / root
0644
format-bytes.js
0.614 KB
7 Dec 2023 1.07 AM
root / root
0644
format-search-stream.js
3.929 KB
7 Dec 2023 1.07 AM
root / root
0644
get-identity.js
0.783 KB
7 Dec 2023 1.07 AM
root / root
0644
is-windows.js
0.228 KB
7 Dec 2023 1.07 AM
root / root
0644
log-file.js
7.032 KB
7 Dec 2023 1.07 AM
root / root
0644
log-shim.js
1.678 KB
7 Dec 2023 1.07 AM
root / root
0644
npm-usage.js
2.041 KB
7 Dec 2023 1.07 AM
root / root
0644
open-url-prompt.js
1.438 KB
7 Dec 2023 1.07 AM
root / root
0644
open-url.js
1.088 KB
7 Dec 2023 1.07 AM
root / root
0644
otplease.js
1.229 KB
7 Dec 2023 1.07 AM
root / root
0644
ping.js
0.246 KB
7 Dec 2023 1.07 AM
root / root
0644
pulse-till-done.js
0.402 KB
7 Dec 2023 1.07 AM
root / root
0644
queryable.js
9.558 KB
7 Dec 2023 1.07 AM
root / root
0644
read-user-info.js
1.996 KB
7 Dec 2023 1.07 AM
root / root
0644
reify-finish.js
0.855 KB
7 Dec 2023 1.07 AM
root / root
0644
reify-output.js
4.968 KB
7 Dec 2023 1.07 AM
root / root
0644
replace-info.js
0.788 KB
7 Dec 2023 1.07 AM
root / root
0644
tar.js
3.899 KB
7 Dec 2023 1.07 AM
root / root
0644
timers.js
2.731 KB
7 Dec 2023 1.07 AM
root / root
0644
update-notifier.js
4.188 KB
7 Dec 2023 1.07 AM
root / root
0644
validate-lockfile.js
0.999 KB
7 Dec 2023 1.07 AM
root / root
0644
web-auth.js
0.545 KB
7 Dec 2023 1.07 AM
root / root
0644

GRAYBYTE WORDPRESS FILE MANAGER @ 2026 CONTACT ME
Static GIF