title: How to return values from an event handler in a promise?
body: <p>I am building a nodeJS app which uses the <a href="https://github.com/nodegit/nodegit" rel="nofollow"><code>nodegit</code></a> npm package. So based on the example in their docs, I have the following chapter. It uses a chain of promises, with what looks like a JQuery event handler. Here is my function:</p>
  
  <pre><code>export function prepareDiffs() {
      var patt = new RegExp('[0-9].[0-9]');
      var results: Array&lt;Commit&gt; = [];
      Git.Repository.open("features/tutorial") // Open the repository directory.
          .then(function (repo) { // Open the master branch.
              return repo.getMasterCommit();
          })
          .then(function (firstCommitOnMaster) { // Display information about commits on master.
              var history = firstCommitOnMaster.history(); // Create a new history event emitter.
  
              history.on("commit", function (commit) { // Listen for commit events from the history.
                  var entry = new Commit();
  
                  entry.hash = commit.sha();
                  var step = patt.exec(commit.message());
  
                  if (step !== null) {
                      entry.step = step.toString();
                  }
                  results.push(entry);
              })
              history.start(); // Start emitting events.
              console.log("return");
          });
  }
  </code></pre>
  
  <p>So putting console.log in the <code>history.on()</code> event handler shows all the info I would want to see. So I am fairly confident in my array pushes. So how can I get the <code>prepareDiffs()</code> function to return the populated <code>results</code> array or at least a promise which resolves to the array? </p>
  
  <p>NB: I am using Typescript targeting es6, so async/await is useable. </p>