你的
runCypherQuery
目前还没有什么特别的东西。为了
await
它,您需要显式指定它返回
Promise
一旦
request
完成。只是
等待
荷兰
async
函数并不意味着
异步
函数在解析之前等待所有异步操作完成。转换基于回调的
请求
给一个
承诺
把那个还给我
承诺
,所以它可以
等待
正确编辑:
module.exports.runCypherQuery = (query) => {
const headers = { Authorization: 'Basic xxx' }
const json = {statements: [{statement: query, parameters: {}}]}
return new Promise((resolve, reject) => {
request.post({uri: uri, headers: headers, json: json}, (err, res, body) => {
if(err) reject(err.message)
//console.log(body)
const data = body.results[0].data
console.log('data:')
console.log(data)
console.log('2')
resolve(data)
})
})
}