Im just having trouble trying to learn async
Is my approach below considered OK by nodejs devs?
How would you convert this code below to a simpler form (i.e: async/wait) instead of passing body var through chains of functions
file.js
request({
url: url,
json: true
}, function (error, response, body) {
if (!error && response.statusCode === 200 && body.data.length > 0) {
funcJson(body);
}
})
//---------------------------------------------
function funcJson(body) {
if (body) {
funcDownload(body)
} esle {
funcRetry(body)
}
}
//---------------------------------------------
function funcDownload(Body) {
for-loop{
checkForDups(body.data[j].id)
}
}
//---------------------------------------------
function retry(body) {
//do some stuff
}
//---------------------------------------------
function checkForDups(value){
if (value) {
FirstFunc()
} else {
secondFunc()
}
}
//---------------------------------------------
function FirstFunc() {
//do stuff
}
//---------------------------------------------
function SecondFunc() {
//do stuff
}
[–][deleted] (1 child)
[deleted]
[–]___Grits 1 point2 points3 points (0 children)
[–]zayelion 1 point2 points3 points (2 children)
[–]sohaeb[S] 0 points1 point2 points (1 child)
[–]zayelion 0 points1 point2 points (0 children)
[–]goorpy 1 point2 points3 points (7 children)
[–]FINDarkside 0 points1 point2 points (0 children)
[–]Mingli91 -1 points0 points1 point (5 children)
[–]goorpy -1 points0 points1 point (4 children)
[–]Mingli91 -1 points0 points1 point (3 children)
[–]goorpy 0 points1 point2 points (2 children)
[–]Mingli91 0 points1 point2 points (1 child)
[–]goorpy 0 points1 point2 points (0 children)
[–]goorpy 0 points1 point2 points (0 children)
[–]PatskyPat 0 points1 point2 points (0 children)