【发布时间】:2017-12-19 16:41:53
【问题描述】:
如何在 timeoutWith (30s) 之前使用 Observables Angular 4.x 监控 http 请求的持续时间?
基本上,我想在 5 秒后触发 Application Insights 中的事件。
我的代码:
this.activatedRoute.queryParams
.subscribe(params => {
this.service.obterContextos(params.IdentificadoresExternos)
.timeoutWith(environment.tempoLimiteCarregamento, Observable.defer(() =>
Observable.throw(this.alertarTimeOut())))
.subscribe(
data => {
});
this.appInsightsService.trackEvent('Telemetria - Cartão de Crédito',
telemetriaAI);
parent.postMessage(response, '*');
});
【问题讨论】:
-
所以您的示例代码超时并在 30 秒后抛出
alertarTimeOut,但您问的是如何在 5 秒后触发事件,而不管 30 秒超时? -
准确。当请求达到 5s 时,我想调用一个自定义函数,因为它已经在超时时完成了
-
我现在了解的少了......所以你希望它在 30 秒后超时,然后等待 5 秒并调用该函数?
-
我们要在等待 30 秒后监控经典超时。但我们还想为应用程序洞察触发一个事件,提醒“看,resquest 已从 5 秒过去”
标签: angular http rxjs angular2-observables