Abstract problem: Every time a source Observable emits and event, a sequence of API calls and Angular services need to be triggered. Some of those invocatio
As far as I understood you, you are concerned about readability and not having to carry the payload from method to method.
Have you ever thought about converting an Observable to a Promise? The important thing here is that the observables must complete so that the promise is fulfilled and can be resolved (is the same as complete but only for promise).
Due to your advice, see above (like with async await) I came to this suggestion.
private async startUpload(event: StartUploadEvent) {
const headers = await this.getAuthenticationHeaders(event).toPromise();
const id = await this.generateUploadId().toPromise();
this.emitUploadStartEvent(id, event);
const pdfId = await this.createPdfDocument(event, headers, id).toPromise();
await this.uploadBilderForPdf(event, pdfId, headers, id).toPromise();
const cloudId = await this.closePdf(headers, pdfId).toPromise();
this.emitUploadDoneEvent(id, event, cloudId)
return cloudId
}
Info: Here you can read what happens if you convert an observable into a promise without having complete the observable: Why converted promise from Subject (Observable) does not work as expected
Note: I'm fulfilling your expectations according
And maybe there are other ways to solve the problem which are not violating common best practices