Simplest way to wait some asynchronous tasks complete, in Javascript?
问题 I want to drop some mongodb collections, but that\'s an asynchronous task. The code will be: var mongoose = require(\'mongoose\'); mongoose.connect(\'mongo://localhost/xxx\'); var conn = mongoose.connection; [\'aaa\',\'bbb\',\'ccc\'].forEach(function(name){ conn.collection(name).drop(function(err) { console.log(\'dropped\'); }); }); console.log(\'all dropped\'); The console displays: all dropped dropped dropped dropped What is the simplest way to make sure all dropped will be printed after