예제 #1
0
    def subscribe(self, channel, callback, create_topic=False):
        class MockMessage(object):
            def __init__(self, message):
                self.data = message

        if channel not in self._messages:
            if create_topic:
                self._messages[channel] = deque()
            else:
                raise TopicNotFound("Topic {} doesn't exist".format(channel))

        future = futures.Future()

        def create_message():
            sleep(0.1)
            while self._messages[channel]:
                r = MockMessage(self._messages[channel].pop())
                try:
                    return callback(r)
                except Exception as exc:
                    future.set_exception(exc)

        thread = threading.Thread(target=create_message)
        thread.start()
        return future
예제 #2
0
    def __init__(self, processing_time, resolve_at_msg_count):
        self._lock = threading.Lock()
        self._processing_time = processing_time
        self._pending_ack = 0
        self.max_pending_ack = 0
        self.completed_calls = 0
        self.seen_message_ids = []

        self._resolve_at_msg_count = resolve_at_msg_count
        self.done_future = futures.Future()
예제 #3
0
def _future(*args, **kwargs):
    return futures.Future(*args, **kwargs)