<commit_before>module.exports = Clock;

var next = (function() {
    if(typeof setImmediate == 'function') { return setImmediate; }

    var nextQueue = [];
    var canPost = (
        typeof postMessage == 'function' &&
        typeof addEventListener == 'function'
    );    
    if(canPost) { addEventListener('rdnxttck', processQueue); }

    processQueue();
    return function(callback) {
        nextQueue.push(callback);
    }

    function processQueue() {
        while(nextQueue[0]) {
            nextQueue.shift()();
        }
        if(canPost) {
            postMessage('rdnxttck', '*');
        } else {
            setTimeout(processQueue, 4);
        }
    }
})();

/**
 * Clock Class
 *
 * Clock is an EventEmitter that emits a tick
 * event for every millisecond. Because the
 * JavaScript VM can not run a tick each
 * millisecond, the tick event is emitted enough
 * times each tick to compensate for the length
 * of each tick of the VM. For example, if a tick
 * of the VM takes 7ms, the tick event will be
 * emitted 7 times the next tick.
 *
 * new(Clock)([Number Hz=1000]) => Clock clock
 */
function Clock(Hz) {

    Hz = Hz || 0;

    var clockTime = Date.now();
    var maxBatchSize = 0;
    var scheduledTicks = 0;
    var paused = true;

    var api = {};
    api.start = start;
    api.stop = stop;
    api.onTick = function() {};
    return api;

    function start() {
        if(!paused) { return; }
        paused = false;
        clockTime = Date.now();
        scheduledTicks = 0;
        exec();
    }

    function stop() {
        paused = true;
    }

    /**
     * Executed each tick of the JavaScript VM by the
     * constructor. Dispatches the tick event. This
     * is a separate function so it can be
     * overwritten.
     */
    function exec() {

        //exit if paused
        if(paused) { return; }

        //if target Hz set 
        if(Hz > 0) {

            //compute clock time and ticks for this batch
            var batchTime = Date.now();
            scheduledTicks += (batchTime - clockTime) * (Hz / 1000);
            var ticks = Math.floor(scheduledTicks);
            scheduledTicks -= ticks;
            clockTime = batchTime;

            //limit the ticks this batch to maxBatchSize
            if(maxBatchSize > 0 && ticks > maxBatchSize) {
                ticks = maxBatchSize;
            }

            //execute each tick
            while(ticks--) { api.onTick(); }

        }

        //max Hz
        else {
            var start = Date.now();
            var iX = 0;
            while(iX < 100 && (Date.now() - start) < 30) {
                api.onTick();
                iX += 1;
            }
        }

        //schedule the next batch
        next(exec);
    }
};<commit_msg>remove postMessage method for clocks<commit_after>module.exports = Clock;

/**
 * Clock Class
 *
 * Clock is an EventEmitter that emits a tick
 * event for every millisecond. Because the
 * JavaScript VM can not run a tick each
 * millisecond, the tick event is emitted enough
 * times each tick to compensate for the length
 * of each tick of the VM. For example, if a tick
 * of the VM takes 7ms, the tick event will be
 * emitted 7 times the next tick.
 *
 * new(Clock)([Number Hz=1000]) => Clock clock
 */
function Clock(Hz) {

    Hz = Hz || 0;

    var clockTime = Date.now();
    var maxBatchSize = 0;
    var scheduledTicks = 0;
    var paused = true;

    var api = {};
    api.start = start;
    api.stop = stop;
    api.onTick = function() {};
    return api;

    function start() {
        if(!paused) { return; }
        paused = false;
        clockTime = Date.now();
        scheduledTicks = 0;
        exec();
    }

    function stop() {
        paused = true;
    }

    /**
     * Executed each tick of the JavaScript VM by the
     * constructor. Dispatches the tick event. This
     * is a separate function so it can be
     * overwritten.
     */
    function exec() {

        //exit if paused
        if(paused) { return; }

        //if target Hz set 
        if(Hz > 0) {

            //compute clock time and ticks for this batch
            var batchTime = Date.now();
            scheduledTicks += (batchTime - clockTime) * (Hz / 1000);
            var ticks = Math.floor(scheduledTicks);
            scheduledTicks -= ticks;
            clockTime = batchTime;

            //limit the ticks this batch to maxBatchSize
            if(maxBatchSize > 0 && ticks > maxBatchSize) {
                ticks = maxBatchSize;
            }

            //execute each tick
            while(ticks--) { api.onTick(); }

        }

        //max Hz
        else {
            var start = Date.now();
            var iX = 0;
            while(iX < 100 && (Date.now() - start) < 30) {
                api.onTick();
                iX += 1;
            }
        }

        //schedule the next batch
        if(typeof setImmediate == 'function') { setImmediate(exec); }
        else if(typeof requestAnimationFrame == 'function') { requestAnimationFrame(exec); }
        else { setTimeout(exec, 0); }
    }
};
{'fraction_non_alphanumeric': 0.11041257367387033, 'fraction_numerical': 0.00962671905697446, 'mean_word_length': 1.7123068726691528, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7102611', 'n_tokens_mistral': 1540, 'n_tokens_neox': 1428, 'n_words': 477}