From ad89c8fb577ac94aafd7fb6e431b3aafdb78860f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A1lint=20Bokros?= Date: Tue, 5 Dec 2017 18:35:22 +0100 Subject: [PATCH] Refactor reset in StatefulEventHandler --- src/event_handlers/stateful_event_handler.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/event_handlers/stateful_event_handler.py b/src/event_handlers/stateful_event_handler.py index 7e47e5a..5ba3bfe 100644 --- a/src/event_handlers/stateful_event_handler.py +++ b/src/event_handlers/stateful_event_handler.py @@ -16,10 +16,7 @@ class StatefulEventHandler(EventHandlerBase): def event_handler_callback(msg_parts): anchor, message = msg_parts if anchor == b'reset': - self.generator = None - self.unsubscribe_all() - self.subscribe(self.anchor) - self.subscribe('reset') + self.reset() return data_json = json.loads(message) if self.generator is None: @@ -36,3 +33,12 @@ class StatefulEventHandler(EventHandlerBase): self.zmq_push_socket.send_multipart(response) self.zmq_sub_stream.on_recv(event_handler_callback) + + def unsubscribe_all(self): + super().unsubscribe_all() + self.subscribe('reset') + + def reset(self): + self.generator = None + self.unsubscribe_all() + self.subscribe(self.anchor)