Make StatefulEventHandler's code clearer

This commit is contained in:
Bálint Bokros 2017-12-05 17:51:34 +01:00
parent ae5e045173
commit 26ef730569

View File

@ -13,7 +13,7 @@ class StatefulEventHandler(EventHandlerBase):
self.generator = None
self.subscribe('reset')
def wrapper(msg_parts, handler):
def event_handler_callback(msg_parts):
anchor, message = msg_parts
if anchor == b'reset':
self.generator = None
@ -23,7 +23,7 @@ class StatefulEventHandler(EventHandlerBase):
return
data_json = json.loads(message)
if self.generator is None:
self.generator = handler(data_json, self)
self.generator = self.event_handler_function(data_json, self)
response_anchor, response_data = next(self.generator)
if response_anchor is None:
return
@ -37,4 +37,4 @@ class StatefulEventHandler(EventHandlerBase):
response = [r.encode('utf-8') for r in (response_anchor, response_data)]
self.zmq_push_socket.send_multipart(response)
self.zmq_sub_stream.on_recv(partial(wrapper, handler=event_handler_function))
self.zmq_sub_stream.on_recv(event_handler_callback)