## 2018-06-25 Generators in #JavaScript 

```javascript
async function* bar() {
  await lively.sleep(2000)
  yield 1;
  await lively.sleep(2000)
  yield 2
  await lively.sleep(2000)
  yield 3;
  await lively.sleep(2000)
  return 4;
}

async function* foo() {
  yield* bar(); // delegates to specified generator
  yield* bar();
}

const div = <div>Hello</div>;
(async () => {
  for await (var x of foo()) {
    div.appendChild(<span>{x}</span>);
  }
})();
div;
```

<script>
async function* bar() {
  await lively.sleep(2000)
  yield 1;
  await lively.sleep(2000)
  yield 2
  await lively.sleep(2000)
  yield 3;
  await lively.sleep(2000)
  return 4;
}

async function* foo() {
  yield* bar(); // delegates to specified generator
  yield* bar();
}

const div = <div>Hello</div>;
(async () => {
  for await (var x of foo()) {
    div.appendChild(<span>{x}</span>);
  }
})();
div;
</script>
