R
R
Roman Rakzin2022-02-19 15:42:16
Angular
Roman Rakzin, 2022-02-19 15:42:16

How to execute a function in RxJs if the BehaviourSubject value is true, and if it is false, then wait until it becomes true?

I have a need to create a subscription and execute the value inside only if the value of another BehaviourSubject is true, and if not, then do not skip, but wait until it becomes true and execute the function ?

In fact, this is necessary when changing the token, since at the first request, if the token is outdated, then you must first update it and put the following requests on hold, and only when the value changes that the token is updated, execute requests.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Shvets, 2022-02-20
@Xuxicheta

source.pipe(
  switchMap( value => myBooleanSubject.pipe(filter(Boolean), mapTo(value)))
)
  .subscribe(value => ...)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question