Commit 94861a3a authored by Nico's avatar Nico
Browse files

Make signal ids stable

This commit makes signal ids stable by always incrementing the id
number.
parent e5557c47
......@@ -16,19 +16,24 @@ class SocketListener(): # pylint: disable=too-few-public-methods
def __init__(self, api):
self._api = api
self._signals = list()
self._signals = dict()
self._signals_lock = Lock()
self._highest_signal_id = -1
self._start_websocket_thread()
def connect(self, event, callback):
self._signals_lock.acquire()
# TODO: Signal ID should be stable after disconnects
signal_id = len(self._signals)
self._signals.append({
signal_id = self._add_signal(event, callback)
self._signals_lock.release()
return signal_id
def _add_signal(self, event, callback):
self._highest_signal_id += 1
signal_id = self._highest_signal_id
self._signals[signal_id] = {
"event": event,
"callback": callback
})
self._signals_lock.release()
}
return signal_id
def _start_websocket_thread(self):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment