blob: a86a224dbb41749aca47ba438c15b9ba639458b2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
var count = 0;
var id;
onmessage = function(evt)
{
try
{
switch(evt.data)
{
case "TimeoutHandler":
count = 0;
id = setTimeout("TimeoutHandler()", 10);
postMessage('hello');
break;
case "IntervalHandler":
count = 0;
id = setInterval("IntervalHandler()", 10);
postMessage('hello');
break;
}
}
catch(ex)
{
postMessage("Fail");
}
}
function TimeoutHandler()
{
count++;
postMessage("worker");
id = setTimeout("TimeoutHandler()", 10);
if (count >= 2)
{
clearTimeout(id);
}
}
function IntervalHandler()
{
count++;
postMessage("worker");
if (count >= 2)
{
clearInterval(id);
}
}
|