0

With Sqlite with nodejs you can't take the call execution order equals to the real db execution order of a query. For example in this pseuso-code you cannot predict if will be inserted A before B or viceversa:

function() {
    db.run("INSERT A", function() { });
    db.run("INSERT B", function() { });
}

But what about the execution order of the callbacks? If the callback of the INSERT A will be called before the callback of INSERT B you can deduce that A will be inserter before B ?

1 Answer 1

2

When the code execution is started then all the callbacks is passed to event queue in FIFO order and event queue watch the current stack execution and if the stack is empty then instantly pass the first position's callback to stack.

So in your case, if the INSERT A callback is called then it executed first after that INSERT B callback executed.

Here is recommended YouTube link https://www.youtube.com/watch?v=8aGhZQkoFbQ to understand the event loop properly you can take a lot of ideas from here since this Guy explained everything in a suitable way

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! I'm watching this good video. So i can take the execution order of callbacks as the real db execution order.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.