首页 > 解决方案 > 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);  
  }
}

标签: javascriptnode.jssqlite

解决方案


推荐阅读