I am currently making a request that returns data for some files and a user.
For each file I want to return an object with data in it but one of the keys is dependent on another request.
How can I make this request so that getData function waits until the inner observable resolves to a value?
function getData() {
return forkJoin([
filesApiRequest),
userApiRquest
])
.pipe(map(([files, userInfo]) => {
return files.getFilesList()
.map((file) => {
const name = file.getName();
const importantInfo = importantInfoCall(userInfo.name, name); // returns an observable.
// How can I get the value from this before returning? I need this piece of data for each
// file in the files list.
return {
data1,
data2,
name,
...,
hasImportantInfo: importantInfo
};
})
}));
}
switchMap(instead ofmap) in conjunction withforkJoin(returned result ofswitchMap). The idea here is to wait for all thoseimportantInfoCallinvocations (I'm assuming these are async in nature) to complete then do what you need to with the result of every invocation. You may want to pair each invocation result with the relevant file it pertains to as well for context.