title: Why my gulp task doesn't exit after it's done
body: <p>I'm wondering why my gulp task doesn't exit after it's finished. It's causing Travis to fail. </p>
  
  <p>Here's the code.</p>
  
  <pre><code>export function awaitPort(port, max=60) {
    let socket, timeout, interval;
    let deferred = Q.defer();
  
    // Doing waiting
  
    return deferred.promise
  };
  
  import { exec }                   from 'child_process';
  
  let testResults = [];
  const API_V2_TEST_COMMAND = 'mocha test/api/v2 --recursive --compilers js:babel/register';
  
  let testBin = (string) =&gt; {
    return `NODE_ENV=testing ./node_modules/.bin/${string}`;
  };
  
  gulp.task('test:api-v2:safe', ['test:prepare:server'], (done) =&gt; {
    awaitPort(TEST_SERVER_PORT).then(() =&gt; {
      let runner = exec(
        testBin(API_V2_TEST_COMMAND),
        (err, stdout, stderr) =&gt; {
          testResults.push({
            suite: 'API Specs\t',
            pass: testCount(stdout, /(\d+) passing/),
            fail: testCount(stderr, /(\d+) failing/),
            pend: testCount(stdout, /(\d+) pending/)
          });
          done();
        }
      );
      pipe(runner);
    });
  });
  </code></pre>
  
  <p>And after I run the task I can see that the task is done but not exiting.</p>
  
  <pre><code>[00:21:41] Using gulpfile /vagrant/gulpfile.js
  [00:21:41] Starting 'test:prepare:mongo'...
  [00:21:41] Finished 'test:prepare:mongo' after 74 ms
  [00:21:41] Starting 'test:prepare:server'...
  [00:21:41] Finished 'test:prepare:server' after 15 ms
  [00:21:41] Starting 'test:api-v2:safe'...
  [00:22:15] Finished 'test:api-v2:safe' after 34 s
  </code></pre>