I am facing an issue with exiting the Observable stream after 3 seconds if there is no new string input. The problem arises when I paste the same value multiple times, as the distinctUntilChanged
operator prevents the input stream from progressing. I want to set a timeout in case no new string stream passes through. Below is my current code:
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
});