Home:ALL Converter>RxJS timeout is not working

RxJS timeout is not working

Ask Time:2017-02-25T02:50:16         Author:Tumen_t

Json Formatter

I'm trying to exit the Observable stream when it takes longer than 3 seconds. The problem is that when I copy and paste the same value a couple of times, distinctUntilChanged operator does not let the input stream go passed. So I want to time out if no string stream comes passed it. Here is what I have.

        import { Subject } from "rxjs/Subject";
        import "rxjs/add/operator/filter";
        import "rxjs/add/operator/debounceTime";
        import "rxjs/add/operator/distinctUntilChanged";
        import "rxjs/add/operator/switchMap";
        import "rxjs/add/operator/timeout";

        this._searchSubject
        .filter(val => val.length > 0)
        .debounceTime(500)
        .distinctUntilChanged()
        .timeout(3000)
        .switchMap(userSearchInput => {
            ...api call that returns Promise
        })
        .subscribe(searchResults => {
            ...do stuff with the result
        });

Author:Tumen_t,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/42446185/rxjs-timeout-is-not-working
yy