<commit_before>﻿function Task(taskFn, awaitFn) {
	if (typeof taskFn !== 'function')
		throw new TypeError("Invalid type of parameter 'taskFn'!");
	this.thisTaskFn_ = taskFn;
	this.taskArgs_ = Array.prototype.slice.call(arguments, 2, arguments.length);
	this.nextTask_ = null;
	this.awaiting_ = (typeof awaitFn == 'function') ? awaitFn : null;
	
	this.context_ = {};
	this.throuthContext_ = false;
	this.taskResult_ = {};

	this.state_ = null;
	this.timeout_ = null;
	this.timeoutObject_ = null;

	this.throuthTimeout_ = false;
}
Task.prototype = {
	get Result() { 
		return this.taskResult_;
	},
	set Result(val) {
		this.taskResult_ = val;
	},
	get NextTask() {
		return this.nextTask_;
	},
	SetTimeout : function (val) {
		if (val == null || val === undefined)
			this.timeout_ = 0;
		else
			this.timeout_ = val;
		return this;
	},
	get ThrouthTimeout(){ 
		return this.throuthTimeout_;
	},
	set ThrouthTimeout(val) {
		if (typeof val != 'boolean') throw new TypeError('Setter of \'ThrouthTimeout\': setting value is not a Boolean type');
		this.throuthTimeout_ = val;
	},
	get State(){
		return this.state_;
	},
	get ThrouthContext() {
		return this.throuthContext_;
	},
	set ThrouthContext(val) {
		if (typeof val != 'boolean') throw new TypeError('Setter of \'ThrouthContext\': setting value is not a Boolean type');
		this.throuthContext_ = val;
	},
	get Context() {
		return this.context_;
	},
	set Context(val) {
		this.context_ = val;
	},
	get Args() {
		return this.taskArgs_;
	}
}
Task.prototype.Next = function (error) {
	if (this.state_ !== Task.TaskState.TimeIsOut && this.state_ !== Task.TaskState.Faulted && this.state_ !== Task.TaskState.Failed) {
		this.state_ = Task.TaskState.Completed;
	}
	if (this.timeoutObject_ != null && this.timeoutObject_ !== undefined)
		clearTimeout(this.timeoutObject_);
	this.thisTaskFn_ = undefined;
	this.taskArgs_.splice(0, this.taskArgs_.length);

	var lArgs = Array.prototype.slice.call(arguments, 1, arguments.length);
		
	if (error != null && error !== undefined) {
		if (this.awaiting_ !== undefined && this.awaiting_ != null) {
			this.awaiting_.call(null, error, this.Context);
			//this.awaiting_ = null;
			//this.nextTask_ = null;
		}
	}
	else if (this.state_ === Task.TaskState.TimeIsOut) {
		var lError = new TaskTimeoutError("Timeout expired!", this.timeout_); 
		if (this.awaiting_ !== undefined && this.awaiting_ != null) {
			this.awaiting_.call(null, lError, this.Context);
			//this.awaiting_ = null;
			//this.nextTask_ = null;
		}
	}
	else  {
		if (this.nextTask_ == null || this.nextTask_ === undefined) {
			this.awaiting_.apply(null, [null, this.Context].concat(lArgs));
			//this.awaiting_ = null;
		}
		else {
			if (this.ThrouthContext === true) {// сквозной контекст
				this.nextTask_.ThrouthContext = true;
				this.nextTask_.Context = this.Context;
			}
			if (this.ThrouthTimeout === true) {// сквозной таймаут
				this.nextTask_.ThrouthTimeout = true;
				this.nextTask_.SetTimeout(this.timeout_);
			}
			this.nextTask_.Run.apply(this.nextTask_, [this.awaiting_].concat(lArgs));
		}
	}
	this.awaiting_ = null;
	this.nextTask_ = null;
}
Task.prototype.Run = function (runArg) {
	if (this.state_ === Task.TaskState.Completed)
		throw new Error('The task can not be started because it already completed.');

	if (typeof runArg == 'function')
		this.awaiting_ = runArg;
	else if (typeof runArg == 'number')
		this.SetTimeout(runArg);
	
	this.Context.task = this;
	
	var lArgs = Array.prototype.slice.call(arguments, 1, arguments.length);
	var lArguments = [ this.Context ].concat(Array.prototype.slice.call(this.taskArgs_, 0, this.taskArgs_.length)).concat(lArgs);
	try {
		this.state_ = Task.TaskState.Runing;<commit_msg>hi.tasks:  fix using special argument in 'Run' operation<commit_after>﻿function Task(taskFn, awaitFn) {
	if (typeof taskFn !== 'function')
		throw new TypeError("Invalid type of parameter 'taskFn'!");
	this.thisTaskFn_ = taskFn;
	this.taskArgs_ = Array.prototype.slice.call(arguments, 2, arguments.length);
	this.nextTask_ = null;
	this.awaiting_ = (typeof awaitFn == 'function') ? awaitFn : null;
	
	this.context_ = {};
	this.throuthContext_ = false;
	this.taskResult_ = {};

	this.state_ = null;
	this.timeout_ = null;
	this.timeoutObject_ = null;

	this.throuthTimeout_ = false;
}
Task.prototype = {
	get Result() { 
		return this.taskResult_;
	},
	set Result(val) {
		this.taskResult_ = val;
	},
	get NextTask() {
		return this.nextTask_;
	},
	SetTimeout : function (val) {
		if (val == null || val === undefined)
			this.timeout_ = 0;
		else
			this.timeout_ = val;
		return this;
	},
	get ThrouthTimeout(){ 
		return this.throuthTimeout_;
	},
	set ThrouthTimeout(val) {
		if (typeof val != 'boolean') throw new TypeError('Setter of \'ThrouthTimeout\': setting value is not a Boolean type');
		this.throuthTimeout_ = val;
	},
	get State(){
		return this.state_;
	},
	get ThrouthContext() {
		return this.throuthContext_;
	},
	set ThrouthContext(val) {
		if (typeof val != 'boolean') throw new TypeError('Setter of \'ThrouthContext\': setting value is not a Boolean type');
		this.throuthContext_ = val;
	},
	get Context() {
		return this.context_;
	},
	set Context(val) {
		this.context_ = val;
	},
	get Args() {
		return this.taskArgs_;
	}
}
Task.prototype.Next = function (error) {
	if (this.state_ !== Task.TaskState.TimeIsOut && this.state_ !== Task.TaskState.Faulted && this.state_ !== Task.TaskState.Failed) {
		this.state_ = Task.TaskState.Completed;
	}
	if (this.timeoutObject_ != null && this.timeoutObject_ !== undefined)
		clearTimeout(this.timeoutObject_);
	this.thisTaskFn_ = undefined;
	this.taskArgs_.splice(0, this.taskArgs_.length);

	var lArgs = Array.prototype.slice.call(arguments, 1, arguments.length);
		
	if (error != null && error !== undefined) {
		if (this.awaiting_ !== undefined && this.awaiting_ != null) {
			this.awaiting_.call(null, error, this.Context);
			//this.awaiting_ = null;
			//this.nextTask_ = null;
		}
	}
	else if (this.state_ === Task.TaskState.TimeIsOut) {
		var lError = new TaskTimeoutError("Timeout expired!", this.timeout_); 
		if (this.awaiting_ !== undefined && this.awaiting_ != null) {
			this.awaiting_.call(null, lError, this.Context);
			//this.awaiting_ = null;
			//this.nextTask_ = null;
		}
	}
	else  {
		if (this.nextTask_ == null || this.nextTask_ === undefined) {
			this.awaiting_.apply(null, [null, this.Context].concat(lArgs));
			//this.awaiting_ = null;
		}
		else {
			if (this.ThrouthContext === true) {// сквозной контекст
				this.nextTask_.ThrouthContext = true;
				this.nextTask_.Context = this.Context;
			}
			if (this.ThrouthTimeout === true) {// сквозной таймаут
				this.nextTask_.ThrouthTimeout = true;
				this.nextTask_.SetTimeout(this.timeout_);
			}
			this.nextTask_.Run.apply(this.nextTask_, [this.awaiting_].concat(lArgs));
		}
	}
	this.awaiting_ = null;
	this.nextTask_ = null;
}
Task.prototype.Run = function (runArg) {
	if (this.state_ === Task.TaskState.Completed)
		throw new Error('The task can not be started because it already completed.');
	
	var lSpecialArg = false;
	if (typeof runArg == 'function')
	{
		this.awaiting_ = runArg;	
		lSpecialArg = true;
	}
	else if (typeof runArg == 'number')
	{
		this.SetTimeout(runArg);
		lSpecialArg = true;
	}
	
	this.Context.task = this;
	
	var lArgs = Array.prototype.slice.call(arguments, lSpecialArg = true ? 1 : 0, arguments.length);
	var lArguments = [ this.Context ].concat(Array.prototype.slice.call(this.taskArgs_, 0, this.taskArgs_.length)).concat(lArgs);
	try {
		this.state_ = Task.TaskState.Runing;
{'fraction_non_alphanumeric': 0.14911352209579254, 'fraction_numerical': 0.0017200317544323895, 'mean_word_length': 3.911630929174789, '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': '167356', 'n_tokens_mistral': 2828, 'n_tokens_neox': 2646, 'n_words': 574}