当前位置: 首页>>代码示例>>Python>>正文


Python Subject.select方法代码示例

本文整理汇总了Python中rx.subjects.Subject.select方法的典型用法代码示例。如果您正苦于以下问题:Python Subject.select方法的具体用法?Python Subject.select怎么用?Python Subject.select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在rx.subjects.Subject的用法示例。


在下文中一共展示了Subject.select方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: WSHandler

# 需要导入模块: from rx.subjects import Subject [as 别名]
# 或者: from rx.subjects.Subject import select [as 别名]
class WSHandler(WebSocketHandler):
    def open(self):
        print("WebSocket opened")

        # A Subject is both an observable and observer, so we can both subscribe
        # to it and also feed (on_next) it with new values
        self.subject = Subject()

        # Get all distinct key up events from the input and only fire if long enough and distinct
        query = self.subject.select(
            lambda x: x["term"]
        ).filter(
            lambda text: len(text) > 2 # Only if the text is longer than 2 characters
        ).throttle(
            0.750, # Pause for 750ms
            scheduler=scheduler
        ).distinct_until_changed() # Only if the value has changed

        searcher = query.flat_map_latest(search_wikipedia)

        def send_response(x):
            self.write_message(x.body)

        def on_error(ex):
            print(ex)

        searcher.subscribe(send_response, on_error)

    def on_message(self, message):
        obj = json_decode(message)
        self.subject.on_next(obj)

    def on_close(self):
        print("WebSocket closed")
开发者ID:jesonjn,项目名称:RxPY,代码行数:36,代码来源:autocomplete_asyncio.py

示例2: WSHandler

# 需要导入模块: from rx.subjects import Subject [as 别名]
# 或者: from rx.subjects.Subject import select [as 别名]
class WSHandler(WebSocketHandler):
    def open(self):
        print("WebSocket opened")

        # A Subject is both an observable and observer, so we can both subscribe 
        # to it and also feed (on_next) it with new values
        self.subject = Subject()

        # Now we take on our magic glasses and project the stream of bytes into 
        # a ...    
        query = self.subject.select(
                lambda obj: obj["keycode"] # 1. stream of keycodes
            ).window_with_count(
                10, 1 # 2. stream of windows (10 ints long)
            ).select_many(
                # 3. stream of booleans, True or False
                lambda win: win.sequence_equal(codes)
            ).where(
                lambda equal: equal # 4. stream of Trues
            )
        # 4. we then subscribe to the Trues, and signal Konami! if we see any
        query.subscribe(lambda x: self.write_message("Konami!"))

    def on_message(self, message):
        obj = json_decode(message)
        self.subject.on_next(obj)

    def on_close(self):
        print("WebSocket closed")
开发者ID:jesonjn,项目名称:RxPY,代码行数:31,代码来源:konamicode.py


注:本文中的rx.subjects.Subject.select方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。