本文整理汇总了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")
示例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")