javascriptnode.jscouchdb-nano

Is this Loop executed synchronous?


i have written this Loop to iterate over some data i've got out of my CouchDB database. I am wondering if this Loop is executed synchronous or if i have to handle it with async/await for example.

database.view('test', 'getAllowedTracker', function(err, body) {
  for(let i = 0; i < body.rows.length; i++){
    let array = body.rows[i].value;
    var newArray = array.filter((value) => value!='tracker8');
    database.atomic('test', 'updatetest', body.rows[i].key, {field: "tracker", value: newArray}).then((response) => {
    });
  }
})

It seems to be synchronous but i am not really sure. If the filter function would be executed after the updating (database.atomic...) that would be fatal.

I am not used to work with asynchronous programming so

Thanks for the help.


Solution

  • In JavaScript for loop and Array.filter() are synchronous. Your code is good there is nothing to worry about.

    JavaScript will run asynchronously in callback and promise. You can Google more about it.