After storing data in the backend, I proceed to retrieve all reserved data for that specific item.
It is crucial that the data retrieval happens only after the reservation process to ensure its inclusion.
Presented with two possible solutions, I am contemplating which one is superior and whether utilizing concat with tap provides any advantages in this scenario:
Using subscription inside another subscription:
...
this.reserveDataItem();
...
reserveDataItem(){
this.myService.reserveData(this.selectedData).subscribe(res => {
if (res.status == 'SUCCESS'){
...logSuccessMessagesAndOtherStuff
}
this.getReservedDataItemsId();
});
}
getReservedDataItemsId(){
this.myService.getReservedDataItemsForRequestId(this.requestId).subscribe(res => {
if (res.status == 'SUCCESS'){
..doStuffWithDataItems
}
});
}
Implementing concat with tap:
I opted for tap due to difficulties in handling multiple return types within a single subscription
and thus, I am curious about any potential benefits of using this method..
...
concat(this.reserveDataItem(), this.getReservedDataItemsId())
.subscribe();
...
reserveDataItem(): Observable<ApiResponseDto<any>>{
return this.myService.reserveData(this.selectedData).pipe(
tap(res => {
if (res.status == 'SUCCESS'){
...logSuccessMessagesAndOtherStuff
}
})
)
}
getReservedDataItemsId():Observable<ApiResponseDto<DataItemDto[]>>{
return this.myService.getReservedDataItemsForRequestId(this.requestId).pipe(
tap(res => {
if (res.status == 'SUCCESS'){
..doStuffWithDataItems
}
})
)
}