sleep is blocking, and not returning controllcontrol to the event loop, so your code just sleeps right where it says sleep.
If you convert it to async, with setTimeout like this:
function getData(key){ console.log("IN FUNCTION " + key); setTimeout(function() { var data = "got data for " + key; things.keep(key, data); console.log("DONE WIH FUNCTION " + key); }, 5000); } I get this output:
start IN FUNCTION one IN FUNCTION two end DONE WIH FUNCTION one got data for one got data for two DONE WIH FUNCTION two Which looks correct to me.