0
votes

I try to forkJoin a custom Observable (rxjs 5.5.6)

import { forkJoin } from 'rxjs/observable/forkJoin';

forkJoin(
  this.resources.loadRefsCatalog()
).subscribe((res) => {
  // I'm never executed :(
});

and the target is

public loadRefsCatalog(): Observable<any> {
  console.log(1);
  return new Observable((observer) => {
    console.log(2);
    // doing something
  });
}

I got well the 1 and 2 in console log but i never fall in the subscribe of the forkJoin.

I try some return with {unsubscribe(){}} and observer.complete() but no change. So i'm stuck without idea of why.

Thanks in advance for any ideas.

// Off course my forkJoin is for multiple queries and others are http observable and run well, but not my own observable. I tried a lot of combination.

1
The observable has to complete for forkJoin to emit. And passing a single observable to forkJoin is somewhat pointless.cartant
Exactly, but documentation don't precise that next() is the key ! So you have to call next(value_to_emit) and complete() if it's finished. And it's work. Thanks for your intervention.Killan

1 Answers

0
votes

Solution is

  public loadRefsCatalog(): Observable<any> {
    return new Observable((observer) => {
      this.dataProvider.loadRefsCatalog().subscribe((res) => {
        this.refsCatalog = res;

        observer.next(true);
        observer.complete();
      });
    });

The key is next(a_value) and complete(), butmostly next() for the forkJoin.

        observer.next(...whatever you want to send to forkJoin...);