You can leverage the timeout
operator of observables, as described below:
return this.http.get('http://api.geonames.org/postalCodeSearchJSON',
{ search: params })
.retryWhen(error => error.delay(500))
.timeout(2000, new Error('delay exceeded')) // <------
.map(res => res.json().postalCodes);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…