I have a function that will optionally set a header with data retrieved from localStorage
. The localStorage
operation returns a promise that I can turn into an Observable. Once the headers are set (or not), I want to make an http request and return the Observable as a result:
let startObs;
if (useHeaders) {
startObs = Observable.fromPromise(this.getStoredHeaders());
}
else {
startObs = Observable.empty();
}
// wait for startObs here
return this.http.get(url, headers);
Essentially I want to wait for startObs
to complete and then return the http.get
Observable. I have tried using something like startObs.concat(this.http.get())
or startObs.switch(this.http.get())
, but this emits from both the source observable and the http.get
observable. I only want to emit the http.get
Observable.
Is there any way to subscribe only to the last observable in a chain while waiting for a previous observable to complete?