我有一个异步函数 web3.eth.net.isListening()
web3.eth.net.isListening()
await web3.eth.net.isListening()
问题: 我们怎样才能让以上这些 await console.log 显示发生了错误?
await
console.log
你可以用 Promise.race() 提供与超时相关的第二个承诺。
Promise.race()
await Promise.race([ web3.eth.net.isListening(), new Promise(function(resolve) { setTimeout(function() { console.log('Timed out'); resolve(); }, 10000); }), ]);