的getAsync功能等则已经被执行后,完成它的执行。一个人应该先完成然后再去另一个?怎么回事?我怎样才能解决这个问题?为什么我的承诺不工作?
function checkRedis() {
\t \t return new Promise(resolve => {
\t \t \t \t \t
\t \t \t redis.set('kleberIsTheBest', 'heSureIs')
\t \t \t \t .then(() => {
\t \t \t \t \t console.log('1')
\t \t \t \t \t redis.getAsync('bananas').then(data => {
\t \t \t \t \t \t if(!data){
\t \t \t \t \t \t \t console.log('I got here bb')
\t \t \t \t \t \t \t resolve('DOWN')
\t \t \t \t \t \t }
\t \t \t \t \t \t console.log(`here is the ${data}`)
\t \t \t \t \t })
\t \t \t \t }) \t
\t \t \t \t .then((x) => {
\t \t \t \t \t console.log('2 ' + x)
\t \t \t \t \t redis.del('kleberIsTheBest')
\t \t \t \t \t console.log('i got here too bb')
\t \t \t \t \t resolve('UP')
\t \t \t \t })
\t \t \t \t .catch(() => {
\t \t \t \t \t console.log('uh oh... something went bad!')
\t \t \t \t \t resolve('DOWN')
\t \t \t \t })
\t \t \t })
\t }
在一个侧面说明,莫非是抓工作的?无法模拟错误落入捕获处理程序。
是应该如何等待的东西,它没有一个参考?你为什么多次调用'resolve'? –
我打电话多次解析,因为它应该根据服务器状态返回UP或DOWN。 –
我不认为你需要调用解决方案。我不认为你需要新的承诺。 redis.set已经创建了一个承诺。 –