Subversion Repositories Applications.papyrus

Rev

Go to most recent revision | Details | 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
 
11
dojo.provide("dojo.lang.timing.Streamer");
12
dojo.require("dojo.lang.timing.Timer");
13
dojo.lang.timing.Streamer = function (input, output, interval, minimum, initialData) {
14
	var self = this;
15
	var queue = [];
16
	this.interval = interval || 1000;
17
	this.minimumSize = minimum || 10;
18
	this.inputFunction = input || function (q) {
19
	};
20
	this.outputFunction = output || function (point) {
21
	};
22
	var timer = new dojo.lang.timing.Timer(this.interval);
23
	var tick = function () {
24
		self.onTick(self);
25
		if (queue.length < self.minimumSize) {
26
			self.inputFunction(queue);
27
		}
28
		var obj = queue.shift();
29
		while (typeof (obj) == "undefined" && queue.length > 0) {
30
			obj = queue.shift();
31
		}
32
		if (typeof (obj) == "undefined") {
33
			self.stop();
34
			return;
35
		}
36
		self.outputFunction(obj);
37
	};
38
	this.setInterval = function (ms) {
39
		this.interval = ms;
40
		timer.setInterval(ms);
41
	};
42
	this.onTick = function (obj) {
43
	};
44
	this.start = function () {
45
		if (typeof (this.inputFunction) == "function" && typeof (this.outputFunction) == "function") {
46
			timer.start();
47
			return;
48
		}
49
		dojo.raise("You cannot start a Streamer without an input and an output function.");
50
	};
51
	this.onStart = function () {
52
	};
53
	this.stop = function () {
54
		timer.stop();
55
	};
56
	this.onStop = function () {
57
	};
58
	timer.onTick = this.tick;
59
	timer.onStart = this.onStart;
60
	timer.onStop = this.onStop;
61
	if (initialData) {
62
		queue.concat(initialData);
63
	}
64
};
65