/**
* Compares configuration values with a timeout for monitoring purposes.
*
* @param {object} configValues - An object containing the configuration values to compare.
* @param {object} expectedValues - An object containing the expected values for comparison.
* @param {number} timeout - The timeout in milliseconds for the comparison.
* @param {function} callback - A callback function to execute if the values do not match within the timeout.
* @returns {Promise<boolean>} A promise that resolves to true if the values match within the timeout,
* and false otherwise.
*/
async function compareConfigValuesWithTimeout(configValues, expectedValues, timeout, callback) {
const startTime = Date.now();
const checkValue = (key) => {
if (configValues[key] !== expectedValues[key]) {
return false;
}
return true;
};
for (const key in expectedValues) {
if (!checkValue(key)) {
if (Date.now() - startTime > timeout) {
await callback(false, key); // Execute callback if timeout is reached
}
return false; // Return false immediately if a mismatch is found
}
}
return true; // Return true if all values match within the timeout
}
Add your comment