xielder

0.0.4 • Public • Published

xielder

A yield expression is only allowed in a generator body. --ts(1163)

But you can xield anywhere.

Install

npm i xielder

Usage

❌ You can not yield in a callback function:

function* x() {
  setInterval(() => {
    yield Date.now();
  }, 1000);
}

for (const d of x) {
  console.log(d);
}

✅ But you can xield in it:

import { xielder } from "xielder";

const x = xielder<number>((xield) => {
  setInterval(() => {
    xield(Date.now());
  }, 1000);
});

for await (const d of x) {
  console.log(d);
}

✅ use close to stop xielding:

import { xielder } from "xielder";

const x = xielder<number>((xield, close) => {
  setInterval(() => {
    xield(Date.now());
  }, 1000);

  setTimeout(() => {
    close();
  }, 15000);
});

for await (const d of x) {
  console.log(d);
}

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i xielder

Weekly Downloads

0

Version

0.0.4

License

MIT

Unpacked Size

4.12 kB

Total Files

5

Last publish

Collaborators

  • sec-ant