From b97608848cf3899654e4e23ebeb1ed832a8e067d Mon Sep 17 00:00:00 2001 From: Carlos E Silva Date: Fri, 10 Nov 2017 00:20:26 -0500 Subject: [PATCH] Add comments --- index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index e0d3ead..b97942f 100644 --- a/index.js +++ b/index.js @@ -34,10 +34,12 @@ let lastRequestTimestamp = null; * @param {String} str The string that will be outputed. */ function updateStatus() { + // If lastRequestTimestamp hasn't been update yet, do nothing. if (lastRequestTimestamp === null) { return; } + // Get the amount of time elapsed since last request. const timeDelta = Date.now() - lastRequestTimestamp; const timeInSeconds = Math.floor(timeDelta / 1000); process.stdout.write(`Status: Device not available. Last request made ${timeInSeconds} seconds ago\r`); @@ -127,8 +129,10 @@ async function requestLoop() { process.stdout.write('Starting program with the following settings:\n'); process.stdout.write(`${JSON.stringify(options, null, 2)}\n`); -// Kick off program. +// Update the display every second. setInterval(() => { updateStatus(); }, 1000); + +// Kick off request recursion. requestLoop();