<commit_before>function createConnection() {
    var connected = false;

    var listeners = [];

    /*
        Messages are of the form:

            {message: 'connected'}
            {message: 'finished'}
            {message: 'info', message: s}
            {message: 'error', message: s}
            {message: 'thread-created', parent: i, child: i, time: t}
            {message: 'token-passed', from: i, to: i, arg: n, time: t}
            {message: 'thread-started', thread: i, worker: w, time: t}
            {message: 'thread-finished', thread: i, time: t}
    */

    function addListener(listener) {
        listeners.push(listener);
    }

    function broadcast(message) {
        _.map(listeners, function(listener) {
            listener(message)
        })
    }

    function info(message) {
        broadcast({message: 'info', text: message});
    }

    function error(message) {
        broadcast({message: 'error', text: message});
    }

    function connect(host) {
        info("connecting to " + host);

        if (host == "example") {
            var messages = exampleTrace;

            function pushMessage(n, time) {
                if (n == messages.length)
                    return;

                var message = messages[n];

                var messageTime = message.time;<commit_msg>Throttling sending of messages, and sending them in batches.<commit_after>function createConnection() {
    var connected = false;

    var listeners = [];

    /*
        Messages are of the form:

            {message: 'connected'}
            {message: 'finished'}
            {message: 'info', message: s}
            {message: 'error', message: s}
            {message: 'thread-created', parent: i, child: i, time: t}
            {message: 'token-passed', from: i, to: i, arg: n, time: t}
            {message: 'thread-started', thread: i, worker: w, time: t}
            {message: 'thread-finished', thread: i, time: t}
    */

    function addListener(listener) {
        listeners.push(listener);
    }

    var messageQueue = [];

    function broadcast(message) {
        messageQueue.push(message);
        broadcastQueue();
    }

    var broadcastQueue = _.throttle(function() {
        _.map(messageQueue, function(message) {
            _.map(listeners, function(listener) { listener(message); });
        });

        messageQueue.length = 0;
    }, 250);

    function info(message) {
        broadcast({message: 'info', text: message});
    }

    function error(message) {
        broadcast({message: 'error', text: message});
    }

    function connect(host) {
        info("connecting to " + host);

        if (host == "example") {
            var messages = exampleTrace;

            function pushMessage(n, time) {
                if (n == messages.length)
                    return;

                var message = messages[n];

                var messageTime = message.time;
{'fraction_non_alphanumeric': 0.13157894736842105, 'fraction_numerical': 0.001367053998632946, 'mean_word_length': 1.92992992992993, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1069380', 'n_tokens_mistral': 819, 'n_tokens_neox': 779, 'n_words': 219}