Subversion Repositories Applications.papyrus

Rev

Rev 1372 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1318 alexandre_ 1
/*
2
	Copyright (c) 2004-2006, The Dojo Foundation
3
	All Rights Reserved.
4
 
5
	Licensed under the Academic Free License version 2.1 or above OR the
6
	modified BSD license. For more information on Dojo licensing, see:
7
 
8
		http://dojotoolkit.org/community/licensing.shtml
9
*/
10
 
1422 alexandre_ 11
 
12
 
1318 alexandre_ 13
dojo.provide("dojo.lang.timing.Streamer");
14
dojo.require("dojo.lang.timing.Timer");
15
dojo.lang.timing.Streamer = function (input, output, interval, minimum, initialData) {
16
	var self = this;
17
	var queue = [];
18
	this.interval = interval || 1000;
19
	this.minimumSize = minimum || 10;
20
	this.inputFunction = input || function (q) {
21
	};
22
	this.outputFunction = output || function (point) {
23
	};
24
	var timer = new dojo.lang.timing.Timer(this.interval);
25
	var tick = function () {
26
		self.onTick(self);
27
		if (queue.length < self.minimumSize) {
28
			self.inputFunction(queue);
29
		}
30
		var obj = queue.shift();
31
		while (typeof (obj) == "undefined" && queue.length > 0) {
32
			obj = queue.shift();
33
		}
34
		if (typeof (obj) == "undefined") {
35
			self.stop();
36
			return;
37
		}
38
		self.outputFunction(obj);
39
	};
40
	this.setInterval = function (ms) {
41
		this.interval = ms;
42
		timer.setInterval(ms);
43
	};
44
	this.onTick = function (obj) {
45
	};
46
	this.start = function () {
47
		if (typeof (this.inputFunction) == "function" && typeof (this.outputFunction) == "function") {
48
			timer.start();
49
			return;
50
		}
51
		dojo.raise("You cannot start a Streamer without an input and an output function.");
52
	};
53
	this.onStart = function () {
54
	};
55
	this.stop = function () {
56
		timer.stop();
57
	};
58
	this.onStop = function () {
59
	};
60
	timer.onTick = this.tick;
61
	timer.onStart = this.onStart;
62
	timer.onStop = this.onStop;
63
	if (initialData) {
64
		queue.concat(initialData);
65
	}
66
};
67