I've come up with a solution.
private retrieveData() {
console.log('Start');
const sub1 = this.http['url1'].get();
const sub2 = this.http['url2'].get();
const sub3 = this.http['url3'].get();
const sub = forkJoin([sub1, sub2, sub3]).subscribe(([res1, res2, res3]) => {
console.log('Merging data');
this.list1 = res1 as ProjectDto[];
this.list2 = res2 as Array<MyTest>;
this.list3 = res3 as Array<MyTest>;
sessionStorage.setItem('a', JSON.stringify(this.list1));
sessionStorage.setItem('b', JSON.stringify(this.list2));
sessionStorage.setItem('c', JSON.stringify(this.list3));
console.log('Data saved successfully');
});
console.log('Process complete');
}
After calling the method, I noticed that two log lines within the forkJoin
were not being triggered. This made me uncertain about whether the data was fetched from the service. I am utilizing rxjs version 5.5.6.
UPDATE:
Upon further inspection, I realized that the logs were indeed being printed, but due to the prolonged execution time of the service. As a result, the issue now revolves around how to ensure synchronous log printing. Currently, 'Start' and 'Process complete' are displayed first.