コード例 #1
0
    def recv_all(self):
        """recv_all()

        Receive a list of all pending messages. The list can be empty.

        """

        # Check queue status, maybe we need to block the sender
        self._check_queue_status()

        # Pop all messages and return as a list
        pop = self._q_in.pop
        packages = [pop() for i in xrange(len(self._q_in))]
        return [self.message_from_bytes(p._data) for p in packages]
コード例 #2
0
ファイル: channels_pubsub.py プロジェクト: ysalmon/pyzo
 def recv_all(self):
     """ recv_all()
     
     Receive a list of all pending messages. The list can be empty.
     
     """
     
     # Check queue status, maybe we need to block the sender
     self._check_queue_status()
     
     # Pop all messages and return as a list
     pop = self._q_in.pop
     packages = [pop() for i in xrange(len(self._q_in))]
     return [self.message_from_bytes(p._data) for p in packages]
コード例 #3
0
    def recv_selected(self):
        """recv_selected()

        Receive a list of messages. Use only after calling
        yoton.select_sub_channel with this channel as one of the arguments.

        The returned messages are all received before the first pending
        message in the other SUB-channels given to select_sub_channel.

        The combination of this method and the function select_sub_channel
        enables users to combine multiple SUB-channels in a way that
        preserves the original order of the messages.

        """

        # No need to check queue status, we've done that in the
        # _get_pending_sequence_numbers() method

        # Prepare
        q = self._q_in
        ref_seq = self._ref_seq
        popped = []

        # Pop all messages that have sequence number lower than reference
        try:
            for i in xrange(len(q)):
                part = q.pop()
                if part._recv_seq > ref_seq:
                    q.insert(part)  # put back in queue
                    break
                else:
                    popped.append(part)
        except IndexError:
            pass

        # Done; return messages
        return [self.message_from_bytes(p._data) for p in popped]
コード例 #4
0
ファイル: channels_pubsub.py プロジェクト: ysalmon/pyzo
 def recv_selected(self):
     """ recv_selected()
     
     Receive a list of messages. Use only after calling
     yoton.select_sub_channel with this channel as one of the arguments.
     
     The returned messages are all received before the first pending
     message in the other SUB-channels given to select_sub_channel.
     
     The combination of this method and the function select_sub_channel
     enables users to combine multiple SUB-channels in a way that
     preserves the original order of the messages.
     
     """
     
     # No need to check queue status, we've done that in the
     # _get_pending_sequence_numbers() method
     
     # Prepare
     q = self._q_in
     ref_seq = self._ref_seq
     popped = []
     
     # Pop all messages that have sequence number lower than reference
     try:
         for i in xrange(len(q)):
             part = q.pop()
             if part._recv_seq > ref_seq:
                 q.insert(part) # put back in queue
                 break
             else:
                 popped.append(part)
     except IndexError:
         pass
     
     # Done; return messages
     return [self.message_from_bytes(p._data) for p in popped]