Learning about the reactive pattern for bulk operations
We have to consider as usual our tasks as streams. The task that we are going to perform is uploading the recipe image in the backend. So, let's imagine a stream called uploadRecipeImage$
that will take the file and the recipe identifier as input and perform an HTTP request. If we have N files to be uploaded, then we will create N streams.
We want to subscribe to all those streams together, but we are not interested in the values emitted from each stream through the process; we only care about the final result (the last emission), whether the file is uploaded successfully, or whether something wrong happens and the upload fails.
Is there an RxJS operator that gathers a list of Observables together to get a cumulative result? Yes, thankfully, we have forkJoin
. Let's understand the role and behavior of this operator.
The forkJoin operator
The forkJoin
operator falls under the category of combination operators...