Pattern for Observables that includes acknowledgement

前端 未结 3 1700
青春惊慌失措
青春惊慌失措 2021-01-21 23:43

I\'m working on something that is recording data coming from a queue. It was easy enough to process the queue into an Observable so that I can have multiple endpoints in my cod

3条回答
  •  天涯浪人
    2021-01-22 00:10

    Isn't this just concatMap?

    // Requests are coming in a stream, with small intervals or without any.
    const requests=Rx.Observable.of(2,1,16,8,16)
        .concatMap(v=>Rx.Observable.timer(1000).mapTo(v));
    
    // Fetch, it takes some time.
    function fetch(query){
      return Rx.Observable.timer(100*query)
          .mapTo('!'+query).startWith('?'+query);
    }
    
    requests.concatMap(q=>fetch(q));
    

    https://rxviz.com/v/Mog1rmGJ

    If you want to allow multiple fetches simultaneously, use mergeMap with concurrency parameter.

提交回复
热议问题