Redux 如何使ngrx效果等待异步函数

Redux 如何使ngrx效果等待异步函数,redux,ngrx,ngrx-effects,Redux,Ngrx,Ngrx Effects,我正在使用node-keytar在电子应用程序中存储代币。它使用承诺,因此我需要等待承诺解决以获得令牌 我试图创建的效果将调用auth服务来获取令牌,然后使用角度http调用将该令牌发送到后端API。这里的问题是调用效果中的服务函数。由于服务功能需要等待响应keytar整个功能必须是async,但据我所知,无法使效果本身与async关键字不同步 我应该在这里使用不同的体系结构吗?我尝试使用.then()并从内部返回成功操作,但这会引发类型错误 影响(当前具有错误类型Observable的不可分配

我正在使用
node-keytar
在电子应用程序中存储代币。它使用承诺,因此我需要等待承诺解决以获得令牌

我试图创建的效果将调用auth服务来获取令牌,然后使用角度
http
调用将该令牌发送到后端API。这里的问题是调用效果中的服务函数。由于服务功能需要等待响应keytar整个功能必须是async,但据我所知,无法使效果本身与
async
关键字不同步

我应该在这里使用不同的体系结构吗?我尝试使用
.then()
并从内部返回成功操作,但这会引发类型错误

影响(当前具有错误
类型Observable的不可分配给类型Observable
):


像这样的东西有用吗

  setAccount$: Observable<Action> = this.actions$.pipe(
    ofType<SetCurrentAccountPending>(AccountActions.ActionTypes.SetCurrentAccountPending),
    switchMap(action => this.accountService.setCurrentAccount(action.payload)),
    map(data => new AccountActions.SetCurrentAccountSuccess(data)),
    catchError(error => of(new AccountActions.SetCurrentAccountFailure()))
  );
setAccount$:Observable=this.actions$.pipe(
类型(AccountActions.ActionTypes.SetCurrentAccountPending),
switchMap(action=>this.accountService.setCurrentAccount(action.payload)),
映射(数据=>new AccountActions.SetCurrentAccountSuccess(数据)),
catchError(错误=>of(new AccountActions.SetCurrentAccountFailure())
);
async setCurrentAccount(id: string) {
    const password = await AccountHandler.getPasswordFromManager(id);
    const body = {password: password};
    return this.httpClient.post(environment.localApi + '/accounts/' + id, body);
}
  setAccount$: Observable<Action> = this.actions$.pipe(
    ofType<SetCurrentAccountPending>(AccountActions.ActionTypes.SetCurrentAccountPending),
    switchMap(action => this.accountService.setCurrentAccount(action.payload)),
    map(data => new AccountActions.SetCurrentAccountSuccess(data)),
    catchError(error => of(new AccountActions.SetCurrentAccountFailure()))
  );