问题描述
它们来自以下代码:
const promiseFeature = new Promise(async (resolve) => {
let objectProfile = await this.userFeaturesRepository.findById(id);
objectProfile = await this.userFeaturesRepository.getProfileObj(myUserFeatures);
await this.userFeaturesRepository.updateById(id,objectProfile);
resolve()
})
const promiseIAM = new Promise(async (resolve) => {
let objectIAM = await this.userIAMRepository.findById(id);
objectIAM = await this.userIAMRepository.getIAMObj(myUserFeatures);
objectIAM.email = objectIAM.email.toLowerCase();
await this.userIAMRepository.updateById(id,objectIAM);
resolve()
})
await Promise.all([promiseFeature,promiseIAM]);
谢谢, 提前。
解决方法
尝试一下:
const promiseFeature = new Promise((resolve) => {
(async() => {
let objectProfile = await this.userFeaturesRepository.findById(id);
objectProfile = await this.userFeaturesRepository.getProfileObj(myUserFeatures);
await this.userFeaturesRepository.updateById(id,objectProfile);
resolve()
})();
})
const promiseIAM = new Promise((resolve) => {
(async() => {
let objectIAM = await this.userIAMRepository.findById(id);
objectIAM = await this.userIAMRepository.getIAMObj(myUserFeatures);
objectIAM.email = objectIAM.email.toLowerCase();
await this.userIAMRepository.updateById(id,objectIAM);
resolve()
})();
})
await Promise.all([promiseFeature,promiseIAM]);
我想这里发生的事情是eslint期望您的promise中的回调函数将返回void
,但是由于它们是async
,因此它们正在返回promise。
请参阅this page from MDN上的“返回值”部分。