root/as3/Thread/branches/soumen/src/org/libspark/thread/IntervalThreadExecutor.as

リビジョン 637, 2.6 kB (コミッタ: yossy, コミット時期: 4 年 前)

Thread(soumen): どきゅどきゅどっきゅん☆ASDoc 完遂

Line 
1 /*
2  * ActionScript Thread Library
3  *
4  * Licensed under the MIT License
5  *
6  * Copyright (c) 2008 BeInteractive! (www.be-interactive.org) and
7  *                    Spark project  (www.libspark.org)
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining a copy
10  * of this software and associated documentation files (the "Software"), to deal
11  * in the Software without restriction, including without limitation the rights
12  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13  * copies of the Software, and to permit persons to whom the Software is
14  * furnished to do so, subject to the following conditions:
15  *
16  * The above copyright notice and this permission notice shall be included in
17  * all copies or substantial portions of the Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25  * THE SOFTWARE.
26  *
27  */
28 package org.libspark.thread
29 {
30         import flash.events.TimerEvent;
31         import flash.utils.Timer;
32        
33         /**
34          * IntervalThreadExecutor クラスは IThreadExecutor インターフェイスの実装クラスで、
35          * 指定された時間の間隔でスレッドを実行します.
36          *
37          * @author      yossy:beinteractive
38          */
39         public class IntervalThreadExecutor implements IThreadExecutor
40         {
41                 /**
42                  * 新しい IntervalThreadExecutor クラスのインスタンスを作成します.
43                  *
44                  * <p>ここで指定された時間の間隔でスレッドが実行されます。</p>
45                  *
46                  * @param       interval        スレッドを実行する時間の間隔 (ミリ秒)
47                  */
48                 public function IntervalThreadExecutor(interval:Number)
49                 {
50                         _timer = new Timer(interval);
51                         _timer.addEventListener(TimerEvent.TIMER, timerHandler);
52                 }
53                
54                 private var _timer:Timer;
55                
56                 /**
57                  * @inheritDoc
58                  */
59                 public function start():void
60                 {
61                         if (_timer.running) {
62                                 return;
63                         }
64                        
65                         _timer.start();
66                 }
67                
68                 /**
69                  * @inheritDoc
70                  */
71                 public function stop():void
72                 {
73                         if (!_timer.running) {
74                                 return;
75                         }
76                        
77                         _timer.stop();
78                 }
79                
80                 /**
81                  * タイマーハンドラ
82                  *
83                  * @private
84                  */
85                 private function timerHandler(e:TimerEvent):void
86                 {
87                         Thread.executeAllThreads();
88                 }
89         }
90 }
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。