I'm having the same issue with RXJS
I'm using angular-auth-oidc-client. To load several configurations, I'm using this factory.
const httpLoaderFactory = (configService: CustomConfigService) => {
return new StsConfigHttpLoader(configService.getConfigs$())
}
@NgModule({
imports:[
AuthModule.forRoot({
loader: {
provide: StsConfigLoader,
useFactory: httpLoaderFactory,
deps: CustomConfigService
}
})
],
//...
})
export class AuthConfigModule{}
This is how the service looks like.
export class CustomConfigService{
getConfigs$(): Observable<OpenIdConfiguration>[] {
//make call to the backend
//generate OpenIdConfiguration object for each client
//return an array of Observable<OpenIdConfiguration>
}
}
To request the list of clients from the backend, I will need to use observable or promise.
The problem is that when I can't use the await keyword without decorating the method with the async keyword as well.
getConfigs$(): Observable<OpenIdConfiguration>[] {
return await somePromise(); /// needs to decorate the method with async
}
The problem with that is the initial calling method is complaining about the type being Promise<T>
instead of T
, in this case Observable<OpenIdConfiguration>[]
.
Using then promise won't work
getConfigs$(): Observable<OpenIdConfiguration>[] {
let result;
somePromise()
.then((r) => result = r);
return result; //this will run before the promise resolves...!!!!!
}
I'm really stuck. Is there a workaround on this situation?
Thanks for helping
EDIT
return this._store.pipe(
select(mySelector), //request data
map((data) => this.transformToConfig(data)
);
if I return this as it is, it will be an Observable<Observable<OpenIdConfiguration>[]>
. The calling method expects a T, i.e. an array of observables.