Looking for a more elegant solution to handle the case where an array of observables is empty in the following TypeScript function. I want the observable to complete when subscribe() is called without the need for an initial check.
I've already implemented a workaround using an if statement, but it's not ideal.
perform_scan_session_uploads(scan_operations: Array<Observable<any>>): Observable<any> {
// TODO: Check the errors in this inner observable.
return from(scan_operations).pipe(
defaultIfEmpty([true]),
concatAll(),
toArray(),
switchMap((result) => this.send_devices(result)),
switchMap((result) => this.check_device_errors(result)),
tap(() => {
console.log('Scan Errors: ', this.scan_errors);
}),
tap(() => this.clean_scan_session_data()),
);
}