【发布时间】:2019-04-18 21:17:00
【问题描述】:
我在后端使用 Angular 7 和 SignalR 进行推送通知。在某个时刻,我收到大量通知,我的应用程序被完全阻止。
signalR 服务组件:
stateChangeNotifier = new Subject<string>();
hubConnection.on("StateChanged", (state: string) => {
this.stateChangeNotifier.next(state); // this fire enormous number of notification which block application
});
另一个订阅事件的组件:
stateChangeNotifier.subscribe(result => {
// here is enormous number of notification
});
有什么方法可以让我在单独的线程中处理这些通知,或者以某种方式收集它们并每两秒只处理最后一个?
【问题讨论】:
-
请分享您的代码
-
读入 rxjs,我想你正在寻找 bufferTime 或 debounceTime 取决于你的需要。但是如果没有您身边的任何实际代码,就很难分辨
-
这里是代码示例。
标签: javascript angular signalr