I wonder why no one have mentioned this simple pattern? :
(function(next) {
//do something
next()
}(function() {
//do some more
}))
Using timeouts just for blindly waiting is bad practice; and involving promises just adds more complexity to the code. In OP's case:
(function(next) {
for(i=0;i<x;i++){
// do something
if (i==x-1) next()
}
}(function() {
// now wait for firstFunction to finish...
// do something else
}))
a small demo -> http://jsfiddle.net/5jdeb93r/