<commit_before>function Event(channel_url, last_known_change) {
    this.url = channel_url;
    this.last_etag = null;
    this.last_change = null;
    this.request = new XMLHttpRequest();
    this.error_count = 0;
    this.handlers = {};
    
    this._timer = null;

    this._register_event();
}

Event.prototype._callback = function() {
	if (this.request.readyState == 4) {
	    if(this.request.status == 200) {
		this.error_count = 0;
		this.last_etag = this.request.getResponseHeader('Etag');
		this.last_change = this.request.getResponseHeader('Last-Modified');

                var data = this.request.responseText;
                // TODO: assert charAt(1) is '\n'
		this.handles(data.charAt(0))(this.request.responseText.slice(2));
		this._register_event();
	    }
	    else {
		// If this is the first error, try again right away
		// If not, delay some time before trying again
		if(this.error_count)
		    this.error_count = Math.min(this.error_count + 1, 10);
		else
		    this.error_count = 1;

		if(this.error_count > 1) {
		    var delay = (this.error_count - 1) * 500;
		    this._timer = setTimeout(this._register_event, delay);
		}
		else
		    this._register_event();
	    }
	}
};

Event.prototype._register_event = function() {
        this.request.open('GET', this.url, true);
        if(this.last_etag)
            this.request.setRequestHeader('If-None-Match', this.last_etag);
        if (this.last_change)
            this.request.setRequestHeader('If-Modified-Since', this.last_change);
        this.request.onreadystatechange = this._callback;
        this.request.send(null);
};

Event.prototype.register_handler = function(id, func) {
    this.handlers[id] = func;
};

Event.prototype.stop = function() {
    clearTimeout(this._timer);
    this.request.abort();
};<commit_msg>Bug fix: binding function.<commit_after>function Event(channel_url, last_known_change) {
    this.url = channel_url;
    this.last_etag = null;
    this.last_change = null;
    this.request = new XMLHttpRequest();
    this.error_count = 0;
    this.handlers = {};
    
    this._timer = null;

    this._register_event();
}

Event.prototype._callback = function() {
	if (this.request.readyState == 4) {
	    if(this.request.status == 200) {
		this.error_count = 0;
		this.last_etag = this.request.getResponseHeader('Etag');
		this.last_change = this.request.getResponseHeader('Last-Modified');

                var data = this.request.responseText;
                // TODO: assert charAt(1) is '\n'
		this.handles(data.charAt(0))(this.request.responseText.slice(2));
		this._register_event();
	    }
	    else {
		// If this is the first error, try again right away
		// If not, delay some time before trying again
		if(this.error_count)
		    this.error_count = Math.min(this.error_count + 1, 10);
		else
		    this.error_count = 1;

		if(this.error_count > 1) {
		    var delay = (this.error_count - 1) * 500;
		    this._timer = setTimeout(this._register_event, delay);
		}
		else
		    this._register_event();
	    }
	}
};

Event.prototype._register_event = function() {
        this.request.open('GET', this.url, true);
        if(this.last_etag)
            this.request.setRequestHeader('If-None-Match', this.last_etag);
        if (this.last_change)
            this.request.setRequestHeader('If-Modified-Since', this.last_change);
        this.request.onreadystatechange = this._callback.bind(this);
        this.request.send(null);
};

Event.prototype.register_handler = function(id, func) {
    this.handlers[id] = func;
};

Event.prototype.stop = function() {
    clearTimeout(this._timer);
    this.request.abort();
};
{'fraction_non_alphanumeric': 0.1371632765255635, 'fraction_numerical': 0.009895547003848268, 'mean_word_length': 2.9468546637744035, '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': '1841980', 'n_tokens_mistral': 1264, 'n_tokens_neox': 1172, 'n_words': 211}