root / trunk / web / dojo / dojox / timing / Streamer.js
History | View | Annotate | Download (1.35 KB)
1 |
/*
|
---|---|
2 |
Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
|
3 |
Available via Academic Free License >= 2.1 OR the modified BSD license.
|
4 |
see: http://dojotoolkit.org/license for details
|
5 |
*/
|
6 |
|
7 |
|
8 |
if(!dojo._hasResource["dojox.timing.Streamer"]){ |
9 |
dojo._hasResource["dojox.timing.Streamer"]=true; |
10 |
dojo.provide("dojox.timing.Streamer");
|
11 |
dojo.require("dojox.timing._base");
|
12 |
dojox.timing.Streamer=function(_1,_2,_3,_4,_5){ |
13 |
var _6=this; |
14 |
var _7=[];
|
15 |
this.interval=_3||1000; |
16 |
this.minimumSize=_4||10; |
17 |
this.inputFunction=_1||function(q){ |
18 |
}; |
19 |
this.outputFunction=_2||function(_8){ |
20 |
}; |
21 |
var _9=new dojox.timing.Timer(this.interval); |
22 |
var _a=function(){ |
23 |
_6.onTick(_6); |
24 |
if(_7.length<_6.minimumSize){
|
25 |
_6.inputFunction(_7); |
26 |
} |
27 |
var _b=_7.shift();
|
28 |
while(typeof (_b)=="undefined"&&_7.length>0){ |
29 |
_b=_7.shift(); |
30 |
} |
31 |
if(typeof (_b)=="undefined"){ |
32 |
_6.stop(); |
33 |
return;
|
34 |
} |
35 |
_6.outputFunction(_b); |
36 |
}; |
37 |
this.setInterval=function(ms){ |
38 |
this.interval=ms;
|
39 |
_9.setInterval(ms); |
40 |
}; |
41 |
this.onTick=function(_c){ |
42 |
}; |
43 |
this.start=function(){ |
44 |
if(typeof (this.inputFunction)=="function"&&typeof (this.outputFunction)=="function"){ |
45 |
_9.start(); |
46 |
return;
|
47 |
} |
48 |
throw new Error("You cannot start a Streamer without an input and an output function."); |
49 |
}; |
50 |
this.onStart=function(){ |
51 |
}; |
52 |
this.stop=function(){ |
53 |
_9.stop(); |
54 |
}; |
55 |
this.onStop=function(){ |
56 |
}; |
57 |
_9.onTick=this.tick;
|
58 |
_9.onStart=this.onStart;
|
59 |
_9.onStop=this.onStop;
|
60 |
if(_5){
|
61 |
_7.concat(_5); |
62 |
} |
63 |
}; |
64 |
} |