孤独プログラマー譚

孤独死が近い。

RxJS 結合オペレータ覚え書き

let obs1 = sto(1)
let obs2 = sto(2)

merge(obs1, obs2).subscribe(cl) // 1秒後に1, 2
concat(obs1, obs2).subscribe(cl) // 1秒後に1, 2秒後に2
forkJoin(obs1, obs2).subscribe(cl) // 1秒後に[1, 2]
zip(of(1,2), of(3,4)).subscribe(cl) // 1秒後に[1, 3] [2, 4]



共通関数。

function sto(x, time = 1000)  {
  const observable = new Observable(subscriber => {
    setTimeout(() => {
      subscriber.next(x)
      subscriber.complete()
    }, time);
  });
  return observable
}

function cl(x) {
  console.log(x)
}