title: Waiting for an Asynchronous method in NodeJS
body: <p>I've looked high and low, and can only find how to write async functions, which I already understand.</p>
  
  <p>What I am trying to do is run an async method in a triggered event [EventEmitter], but such a simple thing seems to be just simply not possible as I can find. </p>
  
  <p>Consider the following...</p>
  
  <pre><code>// Your basic async method..
  function doSomething(callback) {
      var obj = { title: 'hello' };
  
      // Fire an event for event handlers to alter the object.
      // EvenEmitters are called synchronously
      eventobj.emit('alter_object', obj);
  
      callback(null, obj);
  }
  
  // when this event is fired, I want to manipulate the data
  eventobj.on('alter_object', function(obj) {
      obj.title += " world!";
  
      // Calling this async function here means that our
      // event handler will return before our data is retrieved.
      somemodule.asyncFunction(callback(err, data) {
          obj.data = data;
      });
  });
  </code></pre>
  
  <p>As you can see in the last few lines,  the event handler will finish before the object's data property is added.</p>
  
  <p>What I need is something where I can turn the async function into an sync function and get the results there and then.   so for example...</p>
  
  <pre><code>obj.data = somemodule.asyncFunction();
  </code></pre>
  
  <p>I've looked at the <code>wait.for</code> module, the <code>async</code> module, and none of these will not work.  I've even looked into the <code>yield</code> method, but it seems not yet fully implemented into the V8 engine.</p>
  
  <p>I've also tried using a <code>while</code> loop too wait for data to populate, but this just brings with it the CPU overload issue.</p>
  
  <p>Has anyone experienced this and found a design pattern to get around this?</p>