node-sqlite3 icon indicating copy to clipboard operation
node-sqlite3 copied to clipboard

Provide complete call back to serialize/paralleize function

Open bemineni opened this issue 7 years ago • 2 comments

How do we make sure that db#serialize is completed before executing the start timer code again?. I see await/async with a promise to be the only option to fix this. Is there any better way to solve this ?. db#serialize should have provided a completed call back.

db#each has a completed call back, but other db# functions don't provide that option.

I have already pasted this in stack overflow. No solutions yet. Is it possible to provide complete call back to serialize function ?

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);  
  }
}

bemineni avatar Jun 21 '18 03:06 bemineni

You can use a callback in the last statement inside serialize() and use it to resolve a promise or callback into your code

timoch avatar Jun 26 '18 14:06 timoch

That is what I am doing now. It would be convenient to provide a callback.

bemineni avatar Jul 03 '18 18:07 bemineni