相关疑难解决方法(0)

承诺待定

我的代码:

let AuthUser = data => {
  return google.login(data.username, data.password).then(token => { return token } )
}
Run Code Online (Sandbox Code Playgroud)

当我尝试运行这样的东西时:

let userToken = AuthUser(data)
console.log(userToken)
Run Code Online (Sandbox Code Playgroud)

我越来越:

Promise { <pending> }
Run Code Online (Sandbox Code Playgroud)

但为什么?

我的主要目标是将令牌从中google.login(data.username, data.password)返回一个promise,转换为变量.然后才会执行某些操作.

javascript node.js promise

89
推荐指数
4
解决办法
15万
查看次数

为什么我的异步函数返回得太快?

我正在尝试使用异步函数来调用另一个函数内的函数。它看起来像这样:

const getConnectionsWithEmailsHash = async () => {
    const connectionsWithEmails = await parseConnections('./tmp/connections.csv') 
    console.log(connectionsWithEmails)
    return connectionsWithEmails
}

const connectionsWithEmailsHash = getConnectionsWithEmailsHash()
console.log(connectionsWithEmailsHash) 
Run Code Online (Sandbox Code Playgroud)

当我在异步函数中使用 console.log() 时,我得到了我期望的哈希值,但是当我在 console.log() 中调用异步函数的结果时,我得到了未决的承诺。我虽然异步函数的重点是它在调用时等待承诺得到解决,所以我做错了什么?

javascript node.js async-await

1
推荐指数
1
解决办法
858
查看次数

标签 统计

javascript ×2

node.js ×2

async-await ×1

promise ×1