<commit_before>/*jslint evil: true, browser: true, immed: true, passfail: true, undef: true, newcap: true*/
/*global easyXDM, window, escape, unescape, debug */

/**
 * @class easyXDM.stack.ReliableBehavior
 * This is a behavior that tries to make the underlying transport reliable by using acknowledgements.
 * @namespace easyXDM.stack
 * @constructor
 * @param {Object} config The behaviors configuration.
 */
easyXDM.stack.ReliableBehavior = function(config){
    // #ifdef debug
    var trace = debug.getTracer("easyXDM.stack.ReliableBehavior");
    trace("constructor");
    // #endif
    var pub, // the public interface
 callback; // the callback to execute when we have a confirmed success/failure
    var idOut = 0, idIn = 0, currentMessage = "";
    
    return (pub = {
        incoming: function(message, origin){
            // #ifdef debug
            trace("incoming: " + message);
            // #endif
            var indexOf = message.indexOf("_"), ack = message.substring(0, indexOf).split(",");
            message = message.substring(indexOf + 1);
            
            if (ack[0] == idOut) {
                // #ifdef debug
                trace("message delivered");
                // #endif
                currentMessage = "";
                if (callback) {
                    setTimeout(function(){
                        callback(true);
                    }, 0);
                }
            }
            idIn = ack[1];
            if (message.length > 0) {
                // #ifdef debug
                trace("sending ack, and passing on " + message);
                // #endif
                pub.down.outgoing(idIn + "," + idOut + "_" + currentMessage, origin);
                setTimeout(function(){
                    pub.up.incoming(message, origin);
                }, 0);
            }
            
        },<commit_msg>Made some improvements to the ReliableBehavior<commit_after>/*jslint evil: true, browser: true, immed: true, passfail: true, undef: true, newcap: true*/
/*global easyXDM, window, escape, unescape, debug */

/**
 * @class easyXDM.stack.ReliableBehavior
 * This is a behavior that tries to make the underlying transport reliable by using acknowledgements.
 * @namespace easyXDM.stack
 * @constructor
 * @param {Object} config The behaviors configuration.
 */
easyXDM.stack.ReliableBehavior = function(config){
    // #ifdef debug
    var trace = debug.getTracer("easyXDM.stack.ReliableBehavior");
    trace("constructor");
    // #endif
    var pub, // the public interface
 callback; // the callback to execute when we have a confirmed success/failure
    var idOut = 0, idIn = 0, currentMessage = "";
    
    return (pub = {
        incoming: function(message, origin){
            // #ifdef debug
            trace("incoming: " + message);
            // #endif
            var indexOf = message.indexOf("_"), ack = message.substring(0, indexOf).split(",");
            message = message.substring(indexOf + 1);
            
            if (ack[0] == idOut) {
                // #ifdef debug
                trace("message delivered");
                // #endif
                currentMessage = "";
                if (callback) {
                    callback(true);
                }
            }
            if (message.length > 0) {
                // #ifdef debug
                trace("sending ack, and passing on " + message);
                // #endif
                pub.down.outgoing(ack[1] + "," + idOut + "_" + currentMessage, origin);
                if (idIn != ack[1]) {
                    idIn = ack[1];
                    pub.up.incoming(message, origin);
                }
            }
            
        },
{'fraction_non_alphanumeric': 0.12050797081869764, 'fraction_numerical': 0.004863550391786004, 'mean_word_length': 1.6671469740634006, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '3371350', 'n_tokens_mistral': 986, 'n_tokens_neox': 941, 'n_words': 266}