Last active
April 29, 2019 13:30
-
-
Save dbolser/d530d3d54368a1a3d1b3b587e688d7f5 to your computer and use it in GitHub Desktop.
Should I be writing JS like this?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A variable to know when to exit the 'inner' function. When entered = data.length, we know we can safely continue. | |
var entered = 0 | |
var mah_list = [] | |
async function inner(d, dlength){ | |
// SQL2 | |
setTimeout(function(){ | |
console.log('inner', d, dlength) | |
mah_list.push(d) | |
entered++; | |
if (entered==dlength) { | |
console.log("All done"); | |
final(mah_list); | |
} | |
}, 500, d) | |
} | |
async function outer(){ | |
// SQL1 | |
var data = [1, 2, 3, 4] | |
for(d in data) { | |
console.log('outer', d, entered) | |
inner(d, data.length) | |
} | |
} | |
outer() | |
console.log('here already?') | |
final = function (some_list) { | |
console.log('continuing') | |
console.log(some_list) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment