Skip to main content

Command Palette

Search for a command to run...

Promise.all can not work

Published
1 min read
D

I am a developer from Shanghai China.

There is a bug that promise.all can not work, the callback of then, catch, finally method can not be invoked.

 return Promise.all(resPromiseList)
      .then(() => {
        // can not run here sometimes
        this.setState({ loaded: true });
      })
      .catch((e) => {
         // can not get any exception here
      })
      .finally(() => {
        // can not run here sometimes
        this.setState({ loaded: true });
      });

So, what kind of situation can cause this problem ?

any promise in resPromiseList has resolve or reject code, blow is code snippet

       if (!sessionListMap) {
          return Promise.resolve(res);
        }

        sessionListMap[weChatId] = res.data;

        yield put({
          type: '_updateSessionListMap',
          payload: sessionListMap,
        });

        return Promise.resolve(res);
      },
      { type: 'takeLatest' },
    ],

yes, I found that takeLatest word, it eat my promise status.