Javascript 我想让我的中间件等待特定操作完全完成

Javascript 我想让我的中间件等待特定操作完全完成,javascript,reactjs,middleware,redux-saga,thread-synchronization,Javascript,Reactjs,Middleware,Redux Saga,Thread Synchronization,我正在尝试在我的reactjs应用程序中实现刷新令牌功能。 除了我的saga中间件之外,我还创建了一个中间件来拦截每个dipatch操作。 该中间件检查访问令牌的到期时间。如果该令牌已过期,则它会发出一个刷新该令牌的调用,然后在停止的地方继续。 这是我的中间件 const jwtSaga = (store) => (next) => (action) => { const refreshTokenError = (state) => state.refreshToke

我正在尝试在我的reactjs应用程序中实现刷新令牌功能。 除了我的saga中间件之外,我还创建了一个中间件来拦截每个dipatch操作。 该中间件检查访问令牌的到期时间。如果该令牌已过期,则它会发出一个刷新该令牌的调用,然后在停止的地方继续。 这是我的中间件

const jwtSaga = (store) => (next) => (action) => {
  const refreshTokenError = (state) => state.refreshTokenError;
  const token = localStorage.getItem(pamAccessToken);
  if (action.type == "REFRESH_TOKEN_FAILURE") {
    PopUp({
      description:
        "Your Session has expired, please login to pick up where you left off",
      type: "error",
      styleClass: "error-outer",
    });
    store.dispatch(signOutStart());
  }
  else if (
    action.type != "SIGN_OUT_START" &&
    action.type != "SIGN_OUT_SUCCESS" &&
    action.type != "REFRESH_TOKEN_START" &&
    action.type != "REFRESH_TOKEN_SUCCESS" &&
    action.type != "LOGIN_SUCCESS" &&
    action.type != "LOGIN_FAILURE" &&
    action.type != "LOGIN_START"
  ) {
    if (token && jwt_decode(token).exp <= Date.now() / 1000) {
      store.dispatch(refreshTokenStart());
      // take(refreshTokenStart());
    } else {
      next(action);
    }
  } else {
    next(action);
  }
};
const jwtSaga=(存储)=>(下一步)=>(操作)=>{
const refreshttokenerror=(state)=>state.refreshttokenerror;
const-token=localStorage.getItem(pamAccessToken);
if(action.type==“刷新\u令牌\u失败”){
弹出窗口({
说明:
“您的会话已过期,请登录以继续您的会话”,
键入:“错误”,
styleClass:“外部错误”,
});
store.dispatch(signOutStart());
}
否则如果(
action.type!=“注销\u开始”&&
action.type!=“注销成功”&&
action.type!=“刷新\u令牌\u开始”&&
action.type!=“刷新\u令牌\u成功”&&
action.type!=“登录成功”&&
action.type!=“登录失败”&&
action.type!=“登录\u开始”
) {
if(令牌和jwt_解码(令牌).exp