def open(self): scheduler = AsyncIOScheduler(asyncio.get_event_loop()) 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[Dict[str, str]] = 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: HTTPResponse) -> None: self.write_message(x.body) def on_error(ex: Exception): print(ex) searcher.subscribe(on_next=send_response, on_error=on_error, scheduler=scheduler)
def create(): return xs.pipe(_.debounce(60))
def create(): return never().pipe(_.debounce(10))
def create(): return throw(ex).pipe(_.debounce(10))
def create(): return empty().pipe(_.debounce(10))
def create(): return e1.pipe( ops.debounce(5), )