Skip to content

Commit

Permalink
add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
52cik committed May 14, 2018
1 parent f2fbca5 commit e457002
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions index.js
Expand Up @@ -5,17 +5,17 @@ const ms = require('ms');
const debug = require('debug')('maybe:gc');

const defaultRate = 10 * 60 * 1000; // 10 minutes
const queue = [];
let intervalTimes = 0;
let realRate = 0;
const queue = []; // gc objects queue
let intervalTimes = 0; // processing times
let realRate = 0; // the frequency of the first call

/**
* gc
*
* gc function
* @param {object} instance
* @param {function} instance.gc
* @param {string} instance.gcType
* @param {number|string} interval
* @param {string} [instance.gcType]
* @param {number|string} [interval]
* @param {number|string} [rate]
*/
function gc(instance = {}, interval = defaultRate, rate = defaultRate) {
assert(is.function(instance.gc), 'instance.gc must be a function');
Expand All @@ -29,15 +29,15 @@ function gc(instance = {}, interval = defaultRate, rate = defaultRate) {
if (intervalTimes % num !== 0) {
return;
}
debug(`run gc, type: ${instance.gcType || 'unknown'}`);
debug('run gc, type: %s', instance.gcType || 'unknown');
instance.gc();
});

if (realRate === 0) {
realRate = is.string(rate) ? ms(rate) : rate;
const timer = setInterval(() => {
intervalTimes += 1;
queue.forEach(gcQueueHandle => gcQueueHandle());
queue.forEach(handle => handle());
}, realRate);
timer.unref();
}
Expand Down

0 comments on commit e457002

Please sign in to comment.