Skip to content

Instantly share code, notes, and snippets.

@sznurek
Created July 30, 2012 18:37
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 sznurek/3209021 to your computer and use it in GitHub Desktop.
Save sznurek/3209021 to your computer and use it in GitHub Desktop.
class ActionManager(IOBase):
def __init__(self, action, socket, finished_callback=None):
self.action = action
self.socket = socket
self.finished_callback = finished_callback
self.vars = {}
def register(self, fdmanager):
if self.action is None:
return
# It's an ugly hack, but sufficient for presentation purposes
if isinstance(self.action, WriteAction):
fdmanager.register_write(self.socket, self.callback)
elif:
fdmanager.register_read(self.socket, self.callback)
def callback(self):
self.action.run(self.socket, self.vars)
self.action = self.action.next_action
if self.action is None and self.finished_callback:
self.finished_callback()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment