/**
 * functions to do with event loop blocking monitoring. The event loop will block if there are long-running synchronous operations,
 * meaning no other operations would be able to take place in the same node instance until the operation was completed. This is why
 * it's important for operations to be asynchronous. Even if an operation can be done synchronously it should still be coded in an
 * asynchronous way if it is going to block the event loop
 */
"use strict";

/**
 * statt the event loop detection
 */
module.exports.startEventLoopDetection = function() {
    var eventLoopBlockDetectionOptions = config.get("eventLoopBlockDetection");

    if (eventLoopBlockDetectionOptions && eventLoopBlockDetectionOptions.enabled) {
        logger.info("Setting up event loop blocking monitoring");
        var blocked = require('blocked');

        // create a blocked function that will execute whenever the event loop is blocked
        blocked(function(ms){
            if (!ms) {
                ms = 0;
            }

            logger.error('Event Loop Blocked FOR ' + ms + ' milliseconds');
        });
    } else {
        logger.info("No event loop blocking monitoring configured");
    }
};