本文整理汇总了Python中rx.subjects.Subject.pipe方法的典型用法代码示例。如果您正苦于以下问题:Python Subject.pipe方法的具体用法?Python Subject.pipe怎么用?Python Subject.pipe使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rx.subjects.Subject
的用法示例。
在下文中一共展示了Subject.pipe方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: WSHandler
# 需要导入模块: from rx.subjects import Subject [as 别名]
# 或者: from rx.subjects.Subject import pipe [as 别名]
class WSHandler(WebSocketHandler):
def open(self):
scheduler = AsyncIOScheduler()
print("WebSocket opened")
# A Subject is both an observable and observer, so we can both subscribe
# to it and also feed (send) it with new values
self.subject = Subject()
# Get all distinct key up events from the input and only fire if long enough and distinct
searcher = self.subject.pipe(
ops.map(lambda x: x["term"]),
ops.filter(lambda text: len(text) > 2), # Only if the text is longer than 2 characters
ops.debounce(0.750), # Pause for 750ms
ops.distinct_until_changed(), # Only if the value has changed
ops.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, scheduler=scheduler)
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 pipe [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.pipe(
# 1. stream of keycodes
ops.map(lambda obj: obj["keycode"]),
# 2. stream of windows (10 ints long)
ops.window_with_count(10, 1),
# 3. stream of booleans, True or False
ops.flat_map(lambda win: win.pipe(ops.sequence_equal(codes))),
# 4. stream of Trues
ops.filter(lambda equal: equal)
)
# 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")