I have to call a function with the callback in set timeout for that I have written code like this
getData(a, b, function(err, rlt) {
if (err) {
console.log(err)
} else {
// call next function after 35 seconds
settimeout(getData(c, d, function(err, rlt) {
if (err) {
console.log(err)
} else {
// call next function after 10 seconds
settimeout(getData(x, y, function(err, rlt) {
if (err) {
console.log(err)
} else {
console.log(rlt);
}
}), 10000);
}
}), 35000)
}
});
function getData(parms1, parms2;, callback) {
return callback(null, parms1 + parms2);
}
I have written code similar to this but my problem is that set timeout not working its execute function immediately not wait for 35 seconds and 10 seconds.
I don't know what wrong I am doing and if you know any better way to do please help me.
Promiseorasync awaitinstead ofsetTimeout? The code you have shared is fragile and a good example of callback hell.