我正在开发一个可以在iOS上正常运行的应用,但是当我们在Android上运行该应用时,会收到类似我粘贴在此处的警告,并且执行暂停:
Possible Unhandled Promise Rejection (id: 0):
Error: Callback was already called.
Error: Callback was already called.
at blob:http://localhost:8081/3d1448ea-4625-468e-8c56-527626fd00b2:86472:36
at tryCallOne (blob:http://localhost:8081/3d1448ea-4625-468e-8c56-527626fd00b2:16064:14)
at blob:http://localhost:8081/3d1448ea-4625-468e-8c56-527626fd00b2:16165:17
at blob:http://localhost:8081/3d1448ea-4625-468e-8c56-527626fd00b2:2892:21
at _callTimer (blob:http://localhost:8081/3d1448ea-4625-468e-8c56-527626fd00b2:2781:9)
at _callImmediatesPass (blob:http://localhost:8081/3d1448ea-4625-468e-8c56-527626fd00b2:2817:9)
at Object.callImmediates (blob:http://localhost:8081/3d1448ea-4625-468e-8c56-527626fd00b2:3036:14)
at MessageQueue.__callImmediates (blob:http://localhost:8081/3d1448ea-4625-468e-8c56-527626fd00b2:2370:18)
at blob:http://localhost:8081/3d1448ea-4625-468e-8c56-527626fd00b2:2197:18
at MessageQueue.__guardSafe (blob:http://localhost:8081/3d1448ea-4625-468e-8c56-527626fd00b2:2354:11)
at MessageQueue.flushedQueue (blob:http://localhost:8081/3d1448ea-4625-468e-8c56-527626fd00b2:2196:14)
at MessageQueue.callFunctionReturnFlushedQueue (blob:http://localhost:8081/3d1448ea-4625-468e-8c56-527626fd00b2:2165:21)
at http://localhost:8081/debugger-ui/debuggerWorker.js:70:58
console.warn @ blob:http://localhos…-527626fd00b2:54586
onUnhandled @ blob:http://localhos…-527626fd00b2:15912
onUnhandled @ blob:http://localhos…-527626fd00b2:16324
(anonymous) @ blob:http://localhos…6-527626fd00b2:2864
_callTimer @ blob:http://localhos…6-527626fd00b2:2781
callTimers @ blob:http://localhos…6-527626fd00b2:2988
__callFunction @ blob:http://localhos…6-527626fd00b2:2392
(anonymous) @ blob:http://localhos…6-527626fd00b2:2162
__guardSafe @ blob:http://localhos…6-527626fd00b2:2354
callFunctionReturnFlushedQueue @ blob:http://localhos…6-527626fd00b2:2161
(anonymous) @ debuggerWorker.js:70
主要问题是,由于我未在触发错误的行中找到错误所在,所以找不到。另外,我不太确定应该解决什么问题,因为该应用程序在iOS上运行时没有此警告。
我设法隔离了引起麻烦的线路,但不确定如何解决:
async connectChatEngine(chatEngine) {
const response = await new Promise(resolve => chatEngine.on('$.ready', (data) => {
resolve(data);
}));
console.log('ChatEngine ready to go!');
return response;
},
答案 0 :(得分:0)
将await new Promise()
包裹在try{} catch(e){}
中:
async connectChatEngine(chatEngine) {
try{
const response = await new Promise(resolve => chatEngine.on('$.ready', (data) => {
resolve(data);
}));
console.log('ChatEngine ready to go!');
return response;
} catch(e){
//handle failure here
return false;
}
},