【发布时间】:2019-09-22 15:13:50
【问题描述】:
令人惊讶的是,Rxjs 中似乎没有 throttleWhile 运算符。
我的用例很简单:
HTTP 事件,在文件上传过程中发出。
如果事件是HttpEventType.UploadProgress 类型,我想限制它们,如果是HttpEventType.Response,我想限制它们(捕获最终值,即响应)
我的服务电话:
this.httpService
.uploadDocument(file)
.pipe(
throttleTime(200) // <-- would luv throttleWhile here
)
.subscribe((ev: HttpEvent<any>) => {
if (ev.type === HttpEventType.UploadProgress) {
const percentDone = Math.round(100 * ev.loaded / ev.total);
console.log(percentDone);
this.progress = percentDone;
} else if (ev.type === HttpEventType.Response) {
console.log(ev);
}
})
有什么想法吗?
【问题讨论】:
标签: javascript angular typescript rxjs