3 module.exports = prompt => {
4 prompt.timers = prompt.timers || {};
6 let timers = prompt.options.timers;
9 for (let key of Object.keys(timers)) {
10 let opts = timers[key];
11 if (typeof opts === 'number') {
12 opts = { interval: opts };
14 create(prompt, key, opts);
18 function create(prompt, name, options = {}) {
19 let timer = prompt.timers[name] = { name, start: Date.now(), ms: 0, tick: 0 };
20 let ms = options.interval || 120;
21 timer.frames = options.frames || [];
24 let interval = setInterval(() => {
25 timer.ms = Date.now() - timer.start;
31 timer.loading = false;
32 clearInterval(interval);
35 Reflect.defineProperty(timer, 'interval', { value: interval });
36 prompt.once('close', () => timer.stop());