angularjs – 如何在rxjs中使用Observable.interval多个http请求
发布时间:2020-12-17 17:27:47  所属栏目:安全  来源:网络整理 
            导读:我想创建一个HTTP轮询机制,具有以下规则: 并行调用多个http请求(forkJoin) 间隔运行这些请求(轮询) 仅在订户有新数据时才向订户发送数据(不同) 我只用forkJoin(#1)成功了. 仍然需要一些帮助#2 #3 我为此创建了一个plunker, https://embed.plnkr.co/iIe6pi1h
                
                
                
            | 
                         
 我想创建一个HTTP轮询机制,具有以下规则: 
  
  
>并行调用多个http请求(forkJoin) 我只用forkJoin(#1)成功了. 我为此创建了一个plunker, 谢谢你的帮助. 解决方法
 这将是在间隔之上编写forkJoin的问题…… 
  
  
  
        // interval every 10 seconds
Observable.interval(1000)
  // we probably only need one set of AJAX calls running at a time,// so use switchMap here.
  .switchMap(() =>
    // wait for both of these to complete before emitting
    Observable.forkJoin(
      // get posts
      this.searchService.getPosts()
        // if that GET fails handle it somehow (returning an observable)
        .catch(handlePostsErrors),// get comment in parallel to posts
      this.searchService.getPostComment(1)
        // if that GET fails,handle it like above
        .catch(handlePostCommentErrors)
    )
  )
  // posts and comment will come through in an array because of forkJoin
  .subscribe(([posts,comment]) => doSomething(posts,comment))
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!  | 
                  
推荐文章
            站长推荐
            
        热点阅读
            