【发布时间】:2020-07-02 17:36:00
【问题描述】:
我在学习 Promises 方面取得了一些进展,但我不明白为什么 knex 在节点中的行为如此。
我成功接收到一个查询和控制台。将其注销,但是当我运行时
节点文件名.js
成功打印后进程不会退出并停留在那里,就像 Promise 仍然未决一样。 .finally 语句中的 knex.destroy() 不应该结束 Promise 吗?
async function SELECT_ALL_P() {
const transaction = await knex.transaction()
return knex
.select('*')
.from('p')
.then(items => {
return console.log(items)
})
.catch(error => {
console.log(error)
})
.finally(function() {
knex.destroy()
})
}
SELECT_ALL_P()
我尝试过喜欢
.then(items => {
knex.destroy()
return console.log(items)
})
但它也没有奏效。我需要在终端中按 Ctrl+C 来退出节点执行。
【问题讨论】: