title: Simplest way to switch context back and forth (dispatching)
body: <p>I have two classes that perform independent computation. For the sake of simplicity here, I will represent them with functions<code>calc1</code> and <code>calc2</code>. At some random places in each function, I need to sleep for a while. Rather than doing <code>calc1</code> and then <code>calc2</code>, I'd like to switch back and forth between them.</p>
  <p>I could use threads, but it seems to me at first sight overly engineered to do so. In addition, these 2 functions need to be on the main thread, because they deal with user interface. I do not need different threads. I just need to switch from one context to another, and back where we were.</p>
  <p>In python, there is the concept of <code>greenlet</code> (<code>gevent</code>) which allow simple context switching, without being real thread. That would be perfect for my need. Is there such a mechanism in <code>swift</code> ?</p>
  <pre><code>func calc1() {
  ...
  sleep(300) // go to calc2
  ...
  }
  
  func calc2() {
  ...
  sleep(200) // resume calc1
  ...
  }
  </code></pre>