是否可以在knex.js中取消流式,长时间运行的查询?
尝试过stream.emit('close')
,但似乎没有关闭查询,因为knex.destroy()
调用从未解决。
const query = knex('tablename')
const stream = query.stream({ batchSize: 2000 })
process.on('SIGINT', () => stream.emit('close', 128 + 2))
process.on('SIGTERM', () => stream.emit('close', 128 + 15))
stream
.on('data', onData)
.on('close', (exitCode = 0) => {
knex.destroy()
.then(() => console.log('This is never resolved if the query has finished'))
.catch(err => console.error('could not close connection gracefully', err))
console.log('Finished')
process.exitCode = exitCode
})
.on('end', () => {
console.log('End')
stream.emit('close')
})