我正在尝试将此代码更新至版本6,但我无法弄清如何重新编写流程,我认为我需要通过管道传递结果等,但是我看不到如何使用合并,过滤器流程来完成流程,计时器,地图,首先是曾经工作的toPromise()。任何RxJS员工都能教育我或为我指明正确的方向吗?
const chats: chats[] = <chats[]>await Observable.merge(
this.chatService.$chats.filter(chats => chats.length > 0),
Observable.timer(5000).map(x => {
throw 'Timeout'
})
).first().toPromise()
if(chats.find( chat => chat.id === chatId )) {
this.log.log(`Found active chat ${chatId}, navigating to it from push notification...`)
}
尝试:
import { merge, timer } from 'rxjs';
import { filter, first, map, } from 'rxjs/operators';
const chats: chats[] = <chats[]> await merge(
this.chatService.$chat.pipe(
filter(chats => chats.length > 0),
),
timer(5000).pipe(
map(x => {
throw 'Timeout';
}),
),
).pipe(
first(),
).toPromise();
if(chats.find( chat => chat.id === chatId )) {
this.log.log(`Found active chat ${chatId}, navigating to it from push notification...`)
}
您必须通过管道传递运算符,而不是与.
链接起来。