<br><font size=2 face="sans-serif">I'm just getting started with Twisted,
and trying to find</font>
<br><font size=2 face="sans-serif">my way around. I've done quite
a bit of functional </font>
<br><font size=2 face="sans-serif">programming (Haskell), where recursion
is a very</font>
<br><font size=2 face="sans-serif">common idiom. I keep finding myself
heading in that</font>
<br><font size=2 face="sans-serif">direction as I try to understand how
to use Twisted.</font>
<br><font size=2 face="sans-serif">For example, if I wanted to write a
loop in Haskell</font>
<br><font size=2 face="sans-serif">that woke up once a second and did something,
I</font>
<br><font size=2 face="sans-serif">might write</font>
<br>
<br><font size=2 face="sans-serif">main = heartbeat</font>
<br><font size=2 face="sans-serif">heartbeat = do</font>
<br><font size=2 face="sans-serif"> sleep 1000</font>
<br><font size=2 face="sans-serif"> doSomething</font>
<br><font size=2 face="sans-serif"> heartbeat</font>
<br>
<br><font size=2 face="sans-serif">This code first sleeps for one second,
then does</font>
<br><font size=2 face="sans-serif">something, then calls itself. (The
Haskell compiler</font>
<br><font size=2 face="sans-serif">knows how to keep the stack from overflowing
here,</font>
<br><font size=2 face="sans-serif">in case anyone is wondering.)</font>
<br>
<br><font size=2 face="sans-serif">So if I wanted to do something similar
in Twisted,</font>
<br><font size=2 face="sans-serif">my first inclination is to use callLater,</font>
<br>
<br><font size=2 face="sans-serif">def heartbeat(reactor):</font>
<br><font size=2 face="sans-serif"> doSomething()</font>
<br><font size=2 face="sans-serif"> reactor.callLater(1, heartbeat,
reactor)</font>
<br><font size=2 face="sans-serif">reactor.run()<br>
</font>
<br><font size=2 face="sans-serif">But then my head starts hurting, because
I keep </font>
<br><font size=2 face="sans-serif">thinking that I have to set up all the
callbacks</font>
<br><font size=2 face="sans-serif">before I start the reactor. This
code sets callbacks </font>
<br><font size=2 face="sans-serif">at runtime. Will that be a problem?</font>
<br>
<br><font size=2 face="sans-serif">-Rod</font>
<br>
<br><font size=2 face="sans-serif">P.S. I know there's probably a
function somewhere</font>
<br><font size=2 face="sans-serif">in Twisted to do this already, but I'm
not asking how</font>
<br><font size=2 face="sans-serif">to do this particular thing. I'm
really asking if thinking</font>
<br><font size=2 face="sans-serif">in terms of recursion is a useful Twisted
idiom.</font>
<br>