diff --git a/expire-channels.js b/expire-channels.js index fda2c20bb..a37a4677b 100644 --- a/expire-channels.js +++ b/expire-channels.js @@ -78,7 +78,7 @@ nt = nThen(function (w) { store = _store; })); }).nThen(function () { - dirs.forEach(function (dir) { + dirs.forEach(function (dir, dIdx) { queue(function (w) { console.log('recursing into %s', dir); Fs.readdir(Path.join(root, dir), w(function (e, list) { @@ -98,6 +98,11 @@ nt = nThen(function (w) { }); }); }); + if (dIdx === (dirs.length - 1)) { + queue(function () { + store.shutdown(); + }); + } })); }); }); diff --git a/storage/file.js b/storage/file.js index 33df00692..08a9f19cd 100644 --- a/storage/file.js +++ b/storage/file.js @@ -418,6 +418,7 @@ module.exports.create = function ( openFileLimit: conf.openFileLimit || 2048, }; // 0x1ff -> 777 + var it; Fs.mkdir(env.root, 0x1ff, function (err) { if (err && err.code !== 'EEXIST') { // TODO: somehow return a nice error @@ -465,9 +466,12 @@ module.exports.create = function ( if (!isValidChannelId(channelName)) { return void cb(new Error('EINVAL')); } clearChannel(env, channelName, cb); }, + shutdown: function () { + clearInterval(it); + } }); }); - setInterval(function () { + it = setInterval(function () { flushUnusedChannels(env, function () { }); }, 5000); };