title: gulp: how to execute node.js tasks in sequence
body: <p>I have several <a href="http://gulpjs.com/" rel="nofollow noreferrer">gulp</a> subtasks which will keep monitoring files to update. I need them launched up in sequence.</p>
  
  <pre><code>gulp.task('production', ['update-build-info/production:live', 'build-resources/production:live', 'npm-start', 'simulator'], () =&gt; {
    console.log('finished!!!');
  });
  </code></pre>
  
  <p>My questions are:</p>
  
  <ol>
  <li>I use <a href="https://www.npmjs.com/package/gulp-watch" rel="nofollow noreferrer"><code>gulp-watch</code></a> to track files for live update. This will lead to sequential launching failed, because those subtasks will simply return before it completes launching and becomes idle. </li>
  </ol>
  
  <p>How can I arrange those subtask like this:</p>
  
  <pre><code>[start main task]--&gt;[1. update-build-info]
                            |
                      start watching files
                            |
                      update matched files
                            |
                      idle (keep watching)--&gt;[2. build-resources]
                            |                     |
                      update new changes     start watching files
                                                  |
                                             update matched files
                                                  |
                                             idle (keep watching)--&gt;[3. run npm start]
                                                  |                     |                                                            
                                             update new changes     finish launching, idle --&gt; [4. build and launch iOS app]
                                                                        |
                                                                    update new changes
  </code></pre>
  
  <ol start="2">
  <li>Executing shell script <code>npm start</code> will cause the subtask never ends, and lead to the callback will never be called (print <code>finished!!!</code>). If I remove this subtask, the callback will be called again. How can I make the subtask send a <code>completed</code> signal to trigger the callback?</li>
  </ol>
  
  <p>The <code>npm start</code> is <code>babel-node node_modules/react-native/local-cli/cli.js start</code>.</p>
  
  <hr>
  
  <h2>EDIT:</h2>
  
  <p>I've demonstrated why this topic <a href="https://stackoverflow.com/questions/22824546/how-to-run-gulp-tasks-sequentially-one-after-the-other">"How to run Gulp tasks sequentially one after the other"</a> doesn't work for me. I use <a href="https://www.npmjs.com/package/gulp-watch" rel="nofollow noreferrer"><code>gulp-watch</code></a> which will cause async tasks, and I have no idea how to sync them when it initial work is done .</p>
  
  <p>Another watching mechanism using node.js is <code>npm start</code> which will block the task and never end.</p>
  
  <p>I think I need to use RxJS to do the job if there is no way to resolve this problem.</p>