@app.route('/ws')
def handle_websocket():
    wsock = request.environ.get('wsgi.websocket')
    if (not wsock):
        abort(400, 'Expected WebSocket request.')
    stream = Subject()
    query = stream.map((lambda x: x['term'])).filter((lambda text: (len(text) > 2))).debounce(0.75, scheduler=scheduler).distinct_until_changed()
    searcher = query.flat_map_latest((lambda term: WikiFinder(term)))

    def send_response(x):
        wsock.on_next(x)

    def on_error(ex):
        print(ex)
    searcher.subscribe(send_response, on_error)
    while True:
        try:
            message = wsock.receive()
            obj = json.loads(message)
            stream.on_next(obj)
        except WebSocketError:
            break
@app.route('/ws')
def handle_websocket():
    wsock = request.environ.get('wsgi.websocket')
    if (not wsock):
        abort(400, 'Expected WebSocket request.')
    stream = Subject()
    query = stream.map((lambda x: x['term'])).filter((lambda text: (len(text) > 2))).debounce(0.75, scheduler=scheduler).distinct_until_changed()
    searcher = query.flat_map_latest((lambda term: WikiFinder(term)))

    def send_response(x):
        wsock.on_next(x)

    def on_error(ex):
        print(ex)
    searcher.subscribe(send_response, on_error)
    while True:
        try:
            message = wsock.receive()
            obj = json.loads(message)
            stream.on_next(obj)
        except WebSocketError:
            break