remove need for time worker

This commit is contained in:
Matt Walsh 2020-09-04 14:10:26 -05:00
parent 17f35dbaaa
commit f27db7c66e
3 changed files with 0 additions and 162 deletions

View file

@ -1,66 +0,0 @@
var _TimerInfos = [];
var TimerElasped = function (Id)
{
var TimerInfo = _TimerInfos[Id];
if (!TimerInfo)
{
return;
}
this.postMessage({
Action: "ELASPED",
Id: TimerInfo.Id,
RunOnce: TimerInfo.RunOnce,
});
};
this.onmessage = function (e)
{
var Message = e.data;
switch (Message.Action)
{
case "START":
var TimerInfo = {
Id: Message.Id,
RunOnce: Message.RunOnce,
TimeOut: Message.TimeOut,
};
_TimerInfos[Message.Id] = TimerInfo;
if (Message.RunOnce == true)
{
TimerInfo.TimerId = setTimeout(TimerElasped, Message.TimeOut, Message.Id);
}
else
{
TimerInfo.TimerId = setInterval(TimerElasped, Message.TimeOut, Message.Id);
}
break;
case "STOP":
var TimerInfo = _TimerInfos[Message.Id];
if (!TimerInfo)
{
return;
}
if (TimerInfo.RunOnce == true)
{
clearTimeout(TimerInfo.TimerId);
delete _TimerInfos[Message.Id];
}
else
{
clearInterval(TimerInfo.TimerId);
delete _TimerInfos[Message.Id];
}
break;
}
}

View file

@ -1,94 +0,0 @@
if (window.Worker)
{
var _TimerWorkCallBacks = [];
var _TimerIds = 0;
var _TimerWorker = new window.Worker("scripts/TimerWorker.js");
_TimerWorker.onmessage = function (e)
{
var Message = e.data;
switch (Message.Action)
{
case "ELASPED":
var TimerWorkCallBack = _TimerWorkCallBacks[Message.Id];
if (!TimerWorkCallBack)
{
return;
}
var Window = TimerWorkCallBack.Window;
var CallBack = TimerWorkCallBack.CallBack;
var Arguments = TimerWorkCallBack.Arguments;
if (typeof (CallBack) === 'string')
{
CallBack = new Function(CallBack);
}
if (typeof (CallBack) === 'function')
{
CallBack.apply(Window, Arguments);
}
if (Message.RunOnce == true)
{
_clearIntervalWorker(Message.Id);
}
break;
}
};
window.setIntervalWorker = function (CallBack, TimeOut, Arguments)
{
Arguments = Array.prototype.slice.call(arguments).slice(2);
return _setIntervalWorker(false, CallBack, TimeOut, Arguments, window);
};
window.setTimeoutWorker = function (CallBack, TimeOut, Arguments)
{
Arguments = Array.prototype.slice.call(arguments).slice(2);
return _setIntervalWorker(true, CallBack, TimeOut, Arguments, window);
};
var _setIntervalWorker = function (RunOnce, CallBack, TimeOut, Arguments, Window)
{
var Id = ++_TimerIds;
_TimerWorkCallBacks[Id] = {
CallBack: CallBack,
Arguments: Arguments,
Window: Window,
};
_TimerWorker.postMessage({
Action: "START",
RunOnce: RunOnce,
Id: Id,
TimeOut: TimeOut,
});
return Id;
};
window.clearIntervalWorker = function (Id)
{
_clearIntervalWorker(Id);
};
window.clearTimeoutWorker = function (Id)
{
_clearIntervalWorker(Id);
};
var _clearIntervalWorker = function (Id)
{
if (!Id)
{
return;
}
_TimerWorker.postMessage({
Action: "STOP",
Id: Id,
});
delete _TimerWorkCallBacks[Id];
};
}

View file

@ -30,7 +30,6 @@
<script type="text/javascript" src="scripts/vendor/jquery.autocomplete.min.js"></script> <script type="text/javascript" src="scripts/vendor/jquery.autocomplete.min.js"></script>
<script type="text/javascript" src="scripts/vendor/nosleep.min.js"></script> <script type="text/javascript" src="scripts/vendor/nosleep.min.js"></script>
<script type="text/javascript" src="scripts/vendor/jquery.touchSwipe.min.js"></script> <script type="text/javascript" src="scripts/vendor/jquery.touchSwipe.min.js"></script>
<script type="text/javascript" src="scripts/timer.js"></script>
<script type="text/javascript" src="scripts/index.js"></script> <script type="text/javascript" src="scripts/index.js"></script>
<script type="text/javascript" src="scripts/data/states.js"></script> <script type="text/javascript" src="scripts/data/states.js"></script>
<% } else { %> <% } else { %>
@ -39,7 +38,6 @@
<script type="text/javascript" src="scripts/vendor/jquery.autocomplete.min.js"></script> <script type="text/javascript" src="scripts/vendor/jquery.autocomplete.min.js"></script>
<script type="text/javascript" src="scripts/vendor/nosleep.min.js"></script> <script type="text/javascript" src="scripts/vendor/nosleep.min.js"></script>
<script type="text/javascript" src="scripts/vendor/jquery.touchSwipe.min.js"></script> <script type="text/javascript" src="scripts/vendor/jquery.touchSwipe.min.js"></script>
<script type="text/javascript" src="scripts/timer.js"></script>
<script type="text/javascript" src="scripts/index.js"></script> <script type="text/javascript" src="scripts/index.js"></script>
<script type="text/javascript" src="scripts/data/states.js"></script> <script type="text/javascript" src="scripts/data/states.js"></script>
<% } %> <% } %>