Observable.forkJoin() doesn't execute

后端 未结 5 1857
萌比男神i
萌比男神i 2020-12-30 23:42

I have the following code:

//Loop: For each user ID/Role ID, get the data
userMeta.forEach((businessRole) => {
  Observable.forkJoin(
    af.database.obje         


        
5条回答
  •  星月不相逢
    2020-12-31 00:41

    I've faced a similar issue: I was creating a list of observables dynamically and I've noticed that forkjoin() never emits nor completes if the list of observables is empty whereas Promise.all() resolves with an empty list :

    Observable.forkJoin([])
        .subscribe(() => console.log('do something here')); // This is never called
    

    The workaround I've found is to check the length of the list and to not use this operator when it is empty.

    return jobList.length ? Observable.forkJoin(jobList) : Observable.of([]);
    

提交回复
热议问题