K
K
kachurynets2021-03-20 17:13:05
Angular
kachurynets, 2021-03-20 17:13:05

How to display intermediate time in timer rxjs?

const time = 10000;
    return timer(time).pipe(
      takeUntil(this.subject),
      map(() => {
        console.log('end');
      })
    );


Please tell me how to make it possible to display
the value in the console when the time ends and 5 seconds after the start?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Shvets, 2021-03-21
@kachurynets

timer(5001).pipe(
  src => merge(
    src, 
    timer(5000).pipe(
      tap(() => console.log('5s')),
      takeUntil(src),
    ),
  ),
  finalize(() => console.log('end')),
)

In the console, 5 seconds after the subscription, the inscription 5s will appear. If time is less than 5 seconds, then it will not appear, there will only be end

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question