title: How to delay a loop in a generator function in JavaScript?
body: <p>I have written a small generator that simply enumerates a bunch of messages I handed over to it:</p>
  
  <pre><code>'use strict';
  
  const sequential = function * (messages) {
    for (let i = 0; i &lt; messages.length; i++) {
      yield messages[i];
    }
  };
  
  module.exports = sequential;
  </code></pre>
  
  <p>I use it like this:</p>
  
  <pre><code>for (const message of sequential(messages)) {
    // Do something to message...
  }
  </code></pre>
  
  <p>Basically, everything works fine. Now I want the generator to delay the <code>yield</code> calls, e.g. for 100 milliseconds.</p>
  
  <p>The problem is that I can not simply introduce a <code>setTimeout</code> call, as otherwise the <code>yield</code> is not contained any longer in a generator function, but a normal callback.</p>
  
  <p>How can I solve this?</p>