mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-05 23:11:22 +00:00
Make StatefulEventHandler's code clearer
This commit is contained in:
parent
ae5e045173
commit
26ef730569
@ -13,7 +13,7 @@ class StatefulEventHandler(EventHandlerBase):
|
|||||||
self.generator = None
|
self.generator = None
|
||||||
self.subscribe('reset')
|
self.subscribe('reset')
|
||||||
|
|
||||||
def wrapper(msg_parts, handler):
|
def event_handler_callback(msg_parts):
|
||||||
anchor, message = msg_parts
|
anchor, message = msg_parts
|
||||||
if anchor == b'reset':
|
if anchor == b'reset':
|
||||||
self.generator = None
|
self.generator = None
|
||||||
@ -23,7 +23,7 @@ class StatefulEventHandler(EventHandlerBase):
|
|||||||
return
|
return
|
||||||
data_json = json.loads(message)
|
data_json = json.loads(message)
|
||||||
if self.generator is None:
|
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)
|
response_anchor, response_data = next(self.generator)
|
||||||
if response_anchor is None:
|
if response_anchor is None:
|
||||||
return
|
return
|
||||||
@ -37,4 +37,4 @@ class StatefulEventHandler(EventHandlerBase):
|
|||||||
response = [r.encode('utf-8') for r in (response_anchor, response_data)]
|
response = [r.encode('utf-8') for r in (response_anchor, response_data)]
|
||||||
self.zmq_push_socket.send_multipart(response)
|
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)
|
||||||
|
Loading…
Reference in New Issue
Block a user