javascript - sqlite3 nodejs 模块,我们如何等待 db#serialize 完成
问题描述
我们如何确保 db#serialize 在再次执行启动计时器代码之前完成?我看到 await/async 承诺是解决此问题的唯一选择。有没有更好的方法来解决这个问题?db#serialize 应该提供完整的回调。
db#each 已完成回调,但其他 db# 函数不提供该选项。一般来说 d#serialize 应该提供这个选项
function checkLoop()
{
//console.log("Checking for any request to process")
db.serialize(function(){
db.each('select * from prepare_updates where finished_at IS NULL',
function(err, row){
if(err === null )
{
console.log("preparing updates for " + row.id)
// Some processing
}
})
})
console.log("Starting timer again ")
if(!stop)
{
setTimeout(function(){checkLoop()},2000);
}
}
解决方案
推荐阅读
- javascript - 如何在 for 循环中等待响应?
- database - 如何在没有主键的情况下生成 gii crud Yii2?
- apache-camel - Redhat JBoss Fuse & Apache Camel - 如何使用 3 个文件嵌套路由 XML?
- excel - 使用来自变量的数据更新 Excel 用户表单中的多个文本框
- vba - 将已打开的一个数据表中的 VBA 信息复制到其他位置的其他数据表
- magento2 - 如何在 magento 2.2 中调用外部 API?
- mysql - 上周发生了一些事情,但本周没有发生 mysql 查询
- python - 访问 Zarr 中的一个块
- angular - 找不到“AppModule”的 NgModule 元数据中的错误
- c# - 伊朗 ID 序列号的正则表达式