summaryrefslogtreecommitdiffstats
path: root/doc/scriptexamples/signal1.kvs
diff options
context:
space:
mode:
Diffstat (limited to 'doc/scriptexamples/signal1.kvs')
-rw-r--r--doc/scriptexamples/signal1.kvs47
1 files changed, 47 insertions, 0 deletions
diff --git a/doc/scriptexamples/signal1.kvs b/doc/scriptexamples/signal1.kvs
new file mode 100644
index 00000000..7777e679
--- /dev/null
+++ b/doc/scriptexamples/signal1.kvs
@@ -0,0 +1,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)