title: JS events in series & parallel
body: <p>I have a set of events, each one runs on its own timer. I have multiple use cases but for simplicity let's say they are for individual animation events.  Some events run for a specific amount of time, and some for a certain number of iterations.</p>
  
  <p>I want to call events in sequence using callbacks, so that I can be sure the previous task has finished before it kicks off the next.  Add animations I also want to be able to pass parameters to the tasks so that I can control speed for example.  I would end up with something like:</p>
  
  <pre><code>runSequence( task1(10, 3,"test"), task5(3,7), task3())
  </code></pre>
  
  <p>Note: each task() function has it's own setInterval() timer that performs an action.</p>
  
  <p>So I can run group of tasks in sequence in an order of my choosing, each task waiting for the previous one to complete before starting.   I could also initiate a different sequence of tasks like 1 second later that would be running in parallel with the first sequence.</p>
  
  <pre><code>runSequence( task1(10, 3,"test"), task5(3,7), task3())
  wait(1000) // the previous sequence is still running even after this wait period.
  runSequence (task2(), task4(5,7)). //these tasks happen in order
  </code></pre>
  
  <p>I am unsure how to achieve this.  I may be able to come up with something  that works but may not be elegant or the best practice way to do it.</p>
  
  <p>Thanks in advance for any advice!</p>