Как-то так (не проверял):
interface CreateConnectionOptions extends ConnectOptions {
retryCount?: number;
retryDelay?: number;
}
function createConnection(uri: string, {
retryCount = 6,
retryDelay = 1000,
...mongooseConnectOptions
}: CreateConnectionOptions = {}): Observable<Connection> {
let connection$ = defer(() => mongoose.createConnection(uri, mongooseConnectOptions).asPromise());
if (retryCount > 0) {
connection$ = connection$.pipe(retry({
count: retryCount,
delay: retryDelay
}));
}
return connection$.pipe(shareReplay(1));
}