[RxJS] Transformation operator: repeat

Operator repeat() is somewhat similar to retry(), but is not for handling operators. In this lesson we learn how repeat works.

 

var foo = Rx.Observable.interval(500)
  .zip(Rx.Observable.of('a','b','c','d'), (x,y)=>y);

var bar = foo.map(x => x.toUpperCase());

/*
--a--b--c--d|     (foo)
map(toUpperCase)
--A--B--C--D|      (bar)
 repeat
--A--B--C--D--A--B--C--D--A--B--C--D|
*/

var result = bar.repeat(3);

result.subscribe(
  function (x) { console.log('next ' + x); },
  function (err) { console.log('error ' + err); },
  function () { console.log('done'); },
);

 

你可能感兴趣的:([RxJS] Transformation operator: repeat)