import time


class SocketResource(object):
    def __init__(self, context, socket_type, socket_address):
        self.socket = context.socket(socket_type)
        self.socket.connect(socket_address)
        # on the first connect zeromq takes a few msecs to establish the internal pipes so we have to wait a while
        # before sending the first message
        time.sleep(0.100)

    def __del__(self):
        self.socket.close(linger=1000)

    def close(self, linger=1000):
        self.socket.close(linger=linger)
