Skip to content

Commit

Permalink
again
Browse files Browse the repository at this point in the history
  • Loading branch information
msimerson committed Apr 15, 2024
1 parent bab06f0 commit 5aff1f1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
29 changes: 13 additions & 16 deletions configfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,22 +272,19 @@ class cfreader {
if (this._enoent_timer) return
// Create timer
this._enoent_timer = setInterval(() => {
for (const fileOuter of Object.keys(this._enoent_files)) {
/* BLOCK SCOPE */
((file) => {
fs.stat(file, (err) => {
if (err) return
// File now exists
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(
file,
{ persistent: false },
this.on_watch_event(file, args.type, args.options, args.cb),
)
})
})(fileOuter) // END BLOCK SCOPE
for (const file of Object.keys(this._enoent_files)) {
fs.stat(file, (err) => {
if (err) return
// File now exists
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(
file,
{ persistent: false },
this.on_watch_event(file, args.type, args.options, args.cb),
)
})
}
}, 60 * 1000)
this._enoent_timer.unref() // This shouldn't block exit
Expand Down
9 changes: 5 additions & 4 deletions test/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ describe('getDir', function () {
beforeEach(function (done) {
process.env.NODE_ENV = 'test'
process.env.HARAKA = ''
// process.env.WITHOUT_CONFIG_CACHE = '1'
process.env.WITHOUT_CONFIG_CACHE = '1'
clearRequireCache()
this.config = require('../config')
cleanup(done)
Expand Down Expand Up @@ -494,6 +494,7 @@ describe('getDir', function () {
done()
return
}

const self = this
let callCount = 0

Expand All @@ -507,15 +508,15 @@ describe('getDir', function () {
// console.log(files);
assert.equal(err, null)
assert.equal(files.length, 3)
assert.equal(files[0].data, `contents1${os.EOL}`)
assert.equal(files[2].data, `contents3${os.EOL}`)
assert.equal(files[0], `contents1${os.EOL}`)
assert.equal(files[2], `contents3${os.EOL}`)
fs.writeFile(tmpFile, 'contents4\n', (err2) => {
assert.equal(err2, null)
// console.log('file touched, waiting for callback');
})
}
if (callCount === 2) {
assert.equal(files[3].data, 'contents4\n')
assert.equal(files[3], 'contents4\n')
done()
}
})
Expand Down

0 comments on commit 5aff1f1

Please sign in to comment.