summaryrefslogtreecommitdiffstats
path: root/doc/scriptexamples/signal1.kvs
blob: 7777e679814233fc1f3d2c80fc1c9b34a35e274c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# This implements a "fake timer" object that emits the "timeout" signal
# and a target object slot connected to this signal.

# We also test the immediate object deletion...it seems to work

class(faketimer,object)
{
	timerEvent(<timer id>)
	{
		$this->$emit(timeout,$0)
	}
}


class(target,object)
{
	constructor
	{
		$$->%num = 10;
	}

	timerSlot(<timer id>)
	{
		echo "Timer $0 fired $$->%num"
		$$->%num--;
		if($$->%num == 0)
		{
			echo "Deleting sender $$->$signalSender()->$name() : Kaboom!"
			# Immediate sender deletion....
			delete -i $$->$signalSender
			$$->$startTimer(1000)
		}
	}

	timerEvent(<timer id>)
	{
		echo "Deleting self! : Kaboom!"
		delete $this;
	}
}


%source = $new(faketimer,0,sender)
%target = $new(target,0,target)
connect %source timeout %target timerSlot
echo "Starting timer...."
%source->$startTimer(1000)