'Create and return a function for iterating over messages.
@param *types zero or more message types to associate with listener
@return function that yields messages'

def iterator(self, *types):

    queue = Queue()
    closed = []
    def messageGenerator(block=True, timeout=0.1):
        while True:
            try:
                (yield queue.get(block=block, timeout=timeout))
            except (Empty,):
                if closed:
                    break
    self.register(closed.append, 'ConnectionClosed')
    if types:
        self.register(queue.put, *types)
    else:
        self.registerAll(queue.put)
    return messageGenerator
