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