rxjs execute tap only at the first time

前端 未结 6 1144
臣服心动
臣服心动 2020-12-19 02:18

I want to execute tap() only when i get the first emitted value

Something like:

Observable
  .pipe(
     tap(() => { /* execute only when I get th         


        
6条回答
  •  悲&欢浪女
    2020-12-19 02:57

    Apart from the already mentioned options you also use multicast.

    multicast(new Subject(), s => concat(
      s.pipe(
        take(1),
        tap(v => console.log('tap', v)),
      ),
      s
    )
    

    Live demo: https://stackblitz.com/edit/rxjs-shvuxm

提交回复
热议问题