0

我试图将此代码更新到版本 6,但我无法弄清楚如何从阅读和玩耍中重新设计流程, map, first, 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...`)                       
}
4

1 回答 1

0

尝试:

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...`)                       
 }

您必须对运算符进行管道传输,而不是使用..

于 2020-03-10T02:21:14.250 回答