daily pastebin goal
10%
SHARE
TWEET

circuits framework recursive events

a guest Aug 17th, 2016 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import time
  2. from circuits import Component, Debugger, Event
  3.  
  4. class factorial(Event): pass
  5.  
  6. class App(Component):
  7.     def factorial(self, n):
  8.         time.sleep(1)
  9.         if n > 1:
  10.             nn = yield self.call(factorial(n-1))
  11.             yield n * nn.value
  12.         else:
  13.             yield 1
  14.  
  15.     def started(self, *args):
  16.         rv = yield self.call(factorial(5))
  17.         print(rv.value)
  18.         self.stop()
  19.  
  20. (App() + Debugger()).run()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top