An open API service indexing awesome lists of open source software.

https://github.com/sec-ant/xielder

A yield expression is only allowed in a generator body. But you can xield anywhere.
https://github.com/sec-ant/xielder

xield xielder yield

Last synced: 4 months ago
JSON representation

A yield expression is only allowed in a generator body. But you can xield anywhere.

Awesome Lists containing this project

README

          

# xielder

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

But you can **`xield`** anywhere.

## Install

```bash
npm i xielder
```

## Usage

❌ You can not `yield` in a callback function:

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

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

✅ But you can `xield` in it:

```ts
import { xielder } from "xielder";

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

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

✅ use `close` to stop `xield`ing:

```ts
import { xielder } from "xielder";

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

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

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

## License

MIT