I am currently working on a validation process that goes through data in a table row by row. Due to the fact that each row validation requires access to a shared resource, it is crucial that the access to this resource is serialized.
public validate():Observable<boolean>{
const rowValidations:Observable<boolean>[] = dataRows.map(row=>this.validateSingleRow(row);
return forkJoin(...rowValidations).pipe(
map(results=>results.every(r=>r))
)
}
My understanding is that forkJoin
does not wait for each observable to finish before moving on to the next one, unlike concat
, so this approach may fail. On the other hand, concat
serializes all observables into a single stream.
Is there a way to achieve the subscription order of concat
while still obtaining an array of results from each observable like what forkJoin
provides, effectively synchronizing the execution of each inner observable (similar to Java's synchronized validateSingleRow
)?