mailbox.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:Pyrlang 作者: esl 项目源码 文件源码
def receive(self, filter_fn: Callable):
        """ Apply filter to all messages in the inbox, first message for which
            filter returns True will be returned.

            :param filter_fn: A callable which checks if message is desired
                (and returns True) or should be skipped (and returns False)
            :returns: Message, if the filter returned True, otherwise ``None``
                if no message matches or the mailbox was empty
        """
        if self.queue_.empty():
            return None

        # try every element in the queue, get it, check it, place it into the
        # queue end (NOTE: This will mix the messages breaking the order)
        try:
            for i in range(len(self.queue_)):
                m = self.queue_.get_nowait()

                if filter_fn(m):
                    LOG("Mailbox: match return", m)
                    return m

                self.queue_.put(m)

        except queue.Empty:
            pass

        return None
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号