import zmq
from zeromqthreadpool import PullWorkerThread


class PublishEventWorkerThread(PullWorkerThread):
    def __init__(self, context, worker_address, idle_timeout, logger, pub_address):
        super().__init__(context, worker_address, idle_timeout, logger)
        self.pub_socket = context.socket(zmq.PUB)
        self.pub_socket.connect(pub_address)

    def do_work(self, data):
        self.pub_socket.send(data)

    def dispose(self):
        self.pub_socket.close()
