I am trying to make synchronous call to functions in my node js code.
I am calling my functions like this
set_authentication();
set_file();
function set_authentication(){
---
callback function
---
}
I want that my set_authentication() function should execute first completely and then set_file() should start execution but set_file() function start executing before the callback of set_authentication().
I have tried this using async also like
async.series(
[
// Here we need to call next so that async can execute the next function.
// if an error (first parameter is not null) is passed to next, it will directly go to the final callback
function (next) {
set_looker_authentication_token();
},
// runs this only if taskFirst finished without an error
function (next) {
set_view_measure_file();
}
],
function(error, result){
}
);
but it also doesn't work.
I tried promise also
set_authentication().then(set_file(),console.error);
function set_authentication(){
---
callback function
var myFirstPromise = new Promise((resolve, reject) => {
setTimeout(function(){
resolve("Success!");
}, 250);
});
---
}
here I am getting this error:- Cannot read property 'then' of undefined.
I am new to node and js.
then(set_file(),console.error), that will call set_file immediately since you have the()which tells it to call it instead of passing it as a reference:then(set_file,console.error)