K
K
Konstantin2020-04-26 18:53:25
Angular
Konstantin, 2020-04-26 18:53:25

Rxjs thread start on completion?

There are several outgoing requests on the page, for example:

_a$ = of(1).pipe(delay(6000));
    _b$ = of(2).pipe(delay(5000));

There is also a state:

let preloaderState$ = new BehaviorSubject<boolean>(false);


How to change the state preloaderState$if after 2 seconds there is still no response from forkJoin?

forkJoin$ = forkJoin(_a$, _b$);
forkJoin$.subscribe((data) =.> {});


Tried to do like this:

forkJoin(obs)
      .pipe(takeUntil(this.stop$))
      .subscribe(
        () => {
              this.stop$.next();
              this.stop$.complete();
        },
        (error) => console.log("ERROR: " + error)
      );

of(true)
      .pipe(
         delay(2000),
        takeUntil(this.stop$)
      )
      .subscribe(
        () => {
          this.preloaderState$.next(true);
});


But this option causes a lot of difficulties in unsubscribing from all events ...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Shvets, 2020-04-27
@Junart1

request$;
preloaderState$ = concat(
  of(false),
  timer(2000).pipe(mapTo(true), takeUntil(request$)),
  request$.pipe(mapTo(false)),
)

You can also pack in one stream

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question