<commit_before>'use strict';

var uuid = function () {

	function s4 () {

		return Math.floor( ( 1 + Math.random() ) * 0x10000 ).toString( 16 ).substring( 1 );
	};

	return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4();
};

var Timers = new Class( function () {

	this.private.intervals = {};
	this.private.timeouts  = {};

	MCJS.addCleanupTask( function () {

		this.clearAllTasks();

	}.bind( this ) );
} );


/**
 * Clears all currently set timeouts and intervals
 * @global
 * @example
 * clearAllTasks();
 */

Timers.prototype.clearAllTasks = function () {

	for ( var index in this.private.intervals ) {
		this.private.intervals[ index ].cancel();
	}

	this.private.intervals = {};

	for ( var index in this.private.timeouts ) {
		this.private.timeouts[ index ].cancel();
	}

	this.private.timeouts = {};
};


/**
 * Function for causing a callback function to execute after a delay.
 * @global
 * @param {Function} callback - Function to be ran after delay period.
 * @param {Number} delay - How often then callback should be ran in milliseconds.
 * @return {TimeoutObject} timeout - If the target javascript file set module.exports to anything this will be the result of it.
 * @example
 * var timeout = setTimeout( function () {
 *
 * 	doStuff();
 * }, 1000 );
 */

Timers.prototype.setTimeout = function ( callback, delayInMillis ) {

	var delay  = Math.ceil( delayInMillis / 50 ) || 1;
	var id     = uuid();
	var timeout  = org.bukkit.Bukkit.scheduler.runTaskLater( MCJS.getInstance(), function () {

		delete this.private.timeout[ id ];
		callback();
	}.bind( this ), delay );

	this.private.timeout[ id ] = timeout;

	return {
		'type'   : 'timeout',
		'cancel' : function () {

			delete this.private.timeout[ id ];
			timeout.cancel();
		}.bind( this )
	};
};


/**
 * Function for causing a callback function to execute repeatedly after a delay.
 * @global
 * @param {Function} callback - Function to be ran every time after the repeating delay.
 * @param {Number} delay - How often then callback should be ran in milliseconds.
 * @return {IntervalObject} interval - If the target javascript file set module.exports to anything this will be the result of it.
 * @example
 * var interval = setInterval( function () {
 *
 * 	doStuff();
 * }, 1000 );
 */

Timers.prototype.setInterval = function ( callback, intervalInMillis ) {

	var delay  = Math.ceil( intervalInMillis / 50 ) || 1;
	var id     = uuid();
	var interval  = org.bukkit.Bukkit.scheduler.runTaskTimer( MCJS.getInstance(), function () {

		callback( {
			'type'   : 'interval',
			'cancel' : function () {

				delete this.private.intervals[ id ];
				interval.cancel();
			}.bind( this )
		} );
	}.bind( this ), delay, delay );

	this.private.intervals[ id ] = interval;

	return {
		'type'   : 'interval',
		'cancel' : function () {<commit_msg>Timer documentation<commit_after>'use strict';

var uuid = function () {

	function s4 () {

		return Math.floor( ( 1 + Math.random() ) * 0x10000 ).toString( 16 ).substring( 1 );
	};

	return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4();
};

var Timers = new Class( function () {

	this.private.intervals = {};
	this.private.timeouts  = {};

	MCJS.addCleanupTask( function () {

		this.clearAllTasks();

	}.bind( this ) );
} );


/**
 * Clears all currently set timeouts and intervals
 * @global
 * @example
 * clearAllTasks();
 */

Timers.prototype.clearAllTasks = function () {

	for ( var index in this.private.intervals ) {
		this.private.intervals[ index ].cancel();
	}

	this.private.intervals = {};

	for ( var index in this.private.timeouts ) {
		this.private.timeouts[ index ].cancel();
	}

	this.private.timeouts = {};
};


/**
 * Function for causing a callback function to execute after a delay.
 * @global
 * @implements Timers
 * @param {Function} callback - Function to be ran after delay period.
 * @param {Number} delay - How often then callback should be ran in milliseconds.
 * @return {TimeoutObject} timeout - If the target javascript file set module.exports to anything this will be the result of it.
 * @example
 * var timeout = setTimeout( function () {
 *
 * 	doStuff();
 * }, 1000 );
 */

Timers.prototype.setTimeout = function ( callback, delayInMillis ) {

	var delay  = Math.ceil( delayInMillis / 50 ) || 1;
	var id     = uuid();
	var timeout  = org.bukkit.Bukkit.scheduler.runTaskLater( MCJS.getInstance(), function () {

		delete this.private.timeout[ id ];
		callback();
	}.bind( this ), delay );

	this.private.timeout[ id ] = timeout;

	return {
		'type'   : 'timeout',
		'cancel' : function () {

			delete this.private.timeout[ id ];
			timeout.cancel();
		}.bind( this )
	};
};


/**
 * Function for causing a callback function to execute repeatedly after a delay.
 * @global
 * @implements Timers
 * @param {Function} callback - Function to be ran every time after the repeating delay.
 * @param {Number} delay - How often then callback should be ran in milliseconds.
 * @return {IntervalObject} interval - If the target javascript file set module.exports to anything this will be the result of it.
 * @example
 * var interval = setInterval( function () {
 *
 * 	doStuff();
 * }, 1000 );
 */

Timers.prototype.setInterval = function ( callback, intervalInMillis ) {

	var delay  = Math.ceil( intervalInMillis / 50 ) || 1;
	var id     = uuid();
	var interval  = org.bukkit.Bukkit.scheduler.runTaskTimer( MCJS.getInstance(), function () {

		callback( {
			'type'   : 'interval',
			'cancel' : function () {

				delete this.private.intervals[ id ];
				interval.cancel();
			}.bind( this )
		} );
	}.bind( this ), delay, delay );

	this.private.intervals[ id ] = interval;

	return {
		'type'   : 'interval',
		'cancel' : function () {
{'fraction_non_alphanumeric': 0.1517361111111111, 'fraction_numerical': 0.011458333333333333, 'mean_word_length': 3.2674074074074073, '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': '2101978', 'n_tokens_mistral': 1950, 'n_tokens_neox': 1793, 'n_words': 547}