import threading

from PyQt6 import QtCore

from flandre.nodes.Node import Node


class ZMQReceiver(QtCore.QObject):
    zmq_event = QtCore.pyqtSignal('QByteArray')

    def start(self):
        threading.Thread(target=self._execute, daemon=True).start()

    def _execute(self):
        node: Node = self.parent().p
        while True:
            msg = node.recv()
            self.zmq_event.emit(msg.encode_msg())
