Here is my scenario. I have a class for mongodb access. On initialization the connection is made and saved in a ReplaySubject. Consumers get this subject, and use it to do the database reads and writes. At that level it all works as expected.
public getCollection(collectionname: string) {
// console.log('getCollection mongodb', this.mongoclient$);
return this.mongoclient$
.map(db => db.collection(collectionname))
}
The consumer gets the value, then does the reads and writes in an observable chain. The consumer may call this function before the connection is made.
But if I use concatMap in the chain, it works once. Same with other apis that act when the observable completes.
concatMap stops working because the Subject doesn't complete.
So how do I get the value from the Subject in a way that the observable chain completes?
Or maybe I'm doing it wrong. What would be a better way of doing initialization to get a value, an asynchronous process to get the value, where consumers could call for the value before it is acquired?