rxjs:在我发送的第一组中获取重复的 http 请求
rxjs : get duplicate http requests on the first set that I send
我做了这个功能,每次迭代我有 7 个请求,每次 environment.dashboard.frequency 发送,
但一开始,我看到我向服务器发送了 14 个请求,而不是 7 个:
let requests: Observable<ResourceResponse>[] = initRequests(this.durationService.resourceDataDuration)
timer(0, environment.dashboard.frequency)
.pipe(
takeUntil(this.destroy),
startWith(0),
switchMap(() => forkJoin(requests))
)
.subscribe((responsesArr: ResourceResponse[]) => {
this.updateBegin()
for (const response of responsesArr) {
this.durationService.resourceDurationHandler.setPresentedDataRanges(
response,
this.durationService.resourceDataDuration,
this.durationService.resourcePresnetedDataDurations
)
this.updateMany(response.Resource, response.Response, true)
}
this.updateEnd()
requests = initRequests(this.durationService.resourceDataDuration)
})
timer(0, environment.dashboard.frequency)
-> dueTime = 0
-> 不需要 startWith
我做了这个功能,每次迭代我有 7 个请求,每次 environment.dashboard.frequency 发送, 但一开始,我看到我向服务器发送了 14 个请求,而不是 7 个:
let requests: Observable<ResourceResponse>[] = initRequests(this.durationService.resourceDataDuration)
timer(0, environment.dashboard.frequency)
.pipe(
takeUntil(this.destroy),
startWith(0),
switchMap(() => forkJoin(requests))
)
.subscribe((responsesArr: ResourceResponse[]) => {
this.updateBegin()
for (const response of responsesArr) {
this.durationService.resourceDurationHandler.setPresentedDataRanges(
response,
this.durationService.resourceDataDuration,
this.durationService.resourcePresnetedDataDurations
)
this.updateMany(response.Resource, response.Response, true)
}
this.updateEnd()
requests = initRequests(this.durationService.resourceDataDuration)
})
timer(0, environment.dashboard.frequency)
-> dueTime = 0
-> 不需要 startWith