Skip to content

Instantly share code, notes, and snippets.

@prologic
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prologic/f95e2fe451b5a8eccfa9 to your computer and use it in GitHub Desktop.
Save prologic/f95e2fe451b5a8eccfa9 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
from __future__ import print_function
from circuits import Component, Debugger, Event
class condition(Event):
"""condition Event"""
class waiter(Event):
"""waiter Event"""
class notifier(Event):
"""notifier Event"""
class App(Component):
def started(self, *args):
self.fire(waiter())
yield
self.fire(notifier())
yield
raise SystemExit(0)
def waiter(self):
print("I'll wait right here")
yield self.wait("condition")
print("I'm done waiting")
def notifier(self):
print("About to notify")
self.fire(condition())
print("Done notifying")
def generate_events(self, event):
print(".")
event.reduce_time_left(0.1)
(App() + Debugger()).run()
#!/usr/bin/env python
from __future__ import print_function
from circuits import Component, Debugger, Event
class producer(Event):
"""producer Event"""
class work(Event):
"""work Event"""
class Consumer(Component):
def work(self, i):
print("Doing work on {0:d}".format(i))
# XXX: We don't have an asynchronous sleep() :)
class App(Component):
def started(self, *args):
Consumer().register(self)
self.fire(producer())
yield
raise SystemExit(0)
def producer(self):
for i in range(4):
self.fire(work(i))
print("Put {0:d}".format(i))
(App() + Debugger()).run()
@prologic
Copy link
Author

And just for good measure; we're just implemented [async sleep] for circuits: circuits/circuits#62

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment