//タイマー定数
const TIMER_FUNC = 0;
const TIMER_TIME = 1;
const TIMER_START_TIME = 2;
const TIMER_FLG = 3;
const TIMER_VALUE = 4;

function TimerProc(){
	
	this.constructor = function(){
		//タイマーデータ
		this.timerData = [];
	}
	
	//タイマーセット
	this.setTimer = function(funcObj,time,funcValue=null){
		var date_obj = new Date();
		var setData = [funcObj,time,date_obj.getTime(),false,funcValue];
		this.timerData.push(setData);
		if(this.timerData.length==1){
			this.Timer(this.timerData,this);
		}
	}

	//タイマー処理
	this.Timer = function(funcData,_self){
		var timeId = setTimeout(function(){
			var func_value = 0;
			for(var loop = 0;loop<funcData.length;loop++){
				var date_obj = new Date();
				var time1 = funcData[loop][TIMER_START_TIME];
				var time2 = date_obj.getTime();
				var timeprc = time2-time1;
				if(timeprc>=funcData[loop][TIMER_TIME]){
					if(!funcData[loop][TIMER_FLG]){
						if(funcData[loop][TIMER_VALUE]!=null){
							funcData[loop][TIMER_FUNC](funcData[loop][TIMER_VALUE]);
						}else{
							funcData[loop][TIMER_FUNC]();
							console.log("Timer...exec("+func_value+"/"+funcData.length+")");
						}
						funcData[loop][TIMER_FLG] = true;
					}
				}
				if(!funcData[loop][TIMER_FLG])func_value++;
			}
			if(func_value!=0){
				_self.Timer(funcData,_self);
			}else{
				console.log("Timer...clear("+func_value+"/"+funcData.length+")");
				funcData.length = 0;
			}
		},100);
	}
}