Skip to content

Commit

Permalink
group enoent properties
Browse files Browse the repository at this point in the history
  • Loading branch information
msimerson committed Apr 15, 2024
1 parent 6591af8 commit 4fb12e1
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions configfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ class cfreader {
this._config_cache = {}
this._read_args = {}
this._watchers = {}
this._enoent_timer = false
this._enoent_files = {}
this._enoent = { timer: false, files: [] }
this._sedation_timers = {}
this._overrides = {}

Expand Down Expand Up @@ -62,7 +61,7 @@ class cfreader {
for (const candidate of config_dir_candidates) {
try {
const stat = fs.statSync(candidate)
if (stat && stat.isDirectory()) {
if (stat?.isDirectory()) {
this.config_path = candidate
return
}
Expand Down Expand Up @@ -99,6 +98,7 @@ class cfreader {
if (this._sedation_timers[name]) {
clearTimeout(this._sedation_timers[name])
}

this._sedation_timers[name] = setTimeout(() => {
console.log(`Reloading file: ${name}`)
this.load_config(name, type, options)
Expand All @@ -118,7 +118,7 @@ class cfreader {
)
} catch (e) {
if (e.code === 'ENOENT') {
this._enoent_files[name] = true
this._enoent.files[name] = true
this.ensure_enoent_timer()
} else {
console.error(`Error watching file: ${name} : ${e}`)
Expand Down Expand Up @@ -179,7 +179,7 @@ class cfreader {
// ignore error when ENOENT
console.error(`Error watching config file: ${name} : ${e}`)
} else {
this._enoent_files[name] = true
this._enoent.files[name] = true
this.ensure_enoent_timer()
}
}
Expand Down Expand Up @@ -269,14 +269,14 @@ class cfreader {
}

ensure_enoent_timer() {
if (this._enoent_timer) return
if (this._enoent.timer) return
// Create timer
this._enoent_timer = setInterval(() => {
for (const file of Object.keys(this._enoent_files)) {
this._enoent.timer = setInterval(() => {
for (const file of Object.keys(this._enoent.files)) {
fs.stat(file, (err) => {
if (err) return
// File now exists
delete this._enoent_files[file]
delete this._enoent.files[file]
const args = this._read_args[file]
this.load_config(file, args.type, args.options, args.cb)
this._watchers[file] = fs.watch(
Expand All @@ -287,7 +287,7 @@ class cfreader {
})
}
}, 60 * 1000)
this._enoent_timer.unref() // This shouldn't block exit
this._enoent.timer.unref() // This shouldn't block exit
}

get_filetype_reader(type) {
Expand Down

0 comments on commit 4fb12e1

Please sign in to comment.