【发布时间】:2018-03-15 02:09:00
【问题描述】:
我正在订阅 Firebase 的可观察返回值。如果连接出现问题,我希望订阅超时。这样做的正确方法是什么?我尝试了以下方法,但这在我收到最后一个值后 20 秒超时:
let chatSubscription = this.getChats().timeoutWith(20000, Observable.throw(new Error('timeout'))).subscribe(chats => { ... });
//编辑:getChats()
getChats() {
return Observable.create(observer => {
let chatList = this.db.list('/users/' + this.auth.user.uid + '/chats').timeoutWith(20000, Observable.throw(new Error('timeout'))).subscribe(chats => {
observer.next(chats);
});
//keep track of this subscription
this.openSubscriptions.push(chatList);
});
}
【问题讨论】:
-
你能发布你的 getChats() 方法吗
-
当然,之前应该这样做
-
你需要 Observable.create() 包装器吗?你可以只返回 this.db.list(...) observable,然后在你的组件中订阅它吗?
-
不清楚您当前的代码有什么问题。你自己说,它在最后一个值之后超时。那么期望的行为是什么?
-
我省略了一些代码以使其清楚,这使情况变得更糟:) 现在再次添加。 @Tamas,我想在 20 秒后没有收到单个值时超时。
标签: angular ionic-framework firebase-realtime-database rxjs angularfire