Within my TypeScript application, I have come to a stage where one of my methods performs multiple operations with fromPromise
and toPromise
:
myMethod(...): Promise<string> {
return fromPromise(this.someService1.someMethod1(...)).pipe(
mergeMap(param => fromPromise(this.someMethod2(...))),
map(param => getSomethingFromParam(param)),
).toPromise();
}
Both someMethod1
and someMethod2
utilize toPromise
and fromPromise
internally as well.
I acknowledge that the current implementation may seem cluttered, but it is designed to maintain a clean API in each service (for instance, I primarily utilize the promise results from someMethod1
and someMethod2
, so I convert their internal observables to promises and expose them accordingly).
Potentially, I could revamp the entire structure by enhancing my services to offer more specific methods. This would enable me to directly call a method that yields an Observable instead of a Promise.
Hence, my query persists: is such a restructuring necessary?
To elaborate further: at present, the APIs of my services appear tidy, solely showcasing Promises. Nonetheless, dealing with fromPromise
and toPromise
becomes requisite whenever making use of rxjs operators. Unless these maneuvers significantly impact performance, I prefer retaining the existing setup.