title: NodeJS wait for callback to finish on event emit
body: <p>I have and application written in NodeJS with Express and am attempting to use EventEmitter to create a kind of plugin architecture with plugins hooking into the main code by listening to emitted events.</p>
  
  <p>My problem comes when a plugin function makes an async request (to get data from mongo in this case) this causes the plugin code to finish and return control back to the original emitter which will then complete execution, before the async request in the plugin code finishes.</p>
  
  <p>E.g:</p>
  
  <p>Main App:</p>
  
  <pre><code>// We want to modify the request object in the plugin  
  self.emit('plugin-listener', request);
  </code></pre>
  
  <p>Plugin:</p>
  
  <pre><code>// Plugin function listening to 'plugin-listener', 'request' is an arg
  console.log(request);
  
  // Call to DB (async)
  this.getFromMongo(some_data, function(response){
      // this may not get called until the plugin function has finished!
  }
  </code></pre>
  
  <p>My reason for avoiding a callback function back to the main code from the 'getFromMongo' function is that there may be 0 or many plugins listening to the event.  Ideally I want some way to wait for the DB stuff to finish before returning control to the main app</p>
  
  <p>Many Thanks</p>