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.
- Host: GitHub
- URL: https://github.com/sec-ant/xielder
- Owner: Sec-ant
- License: mit
- Created: 2023-07-26T12:15:06.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-06-25T04:40:23.000Z (over 1 year ago)
- Last Synced: 2025-05-22T21:06:51.108Z (5 months ago)
- Topics: xield, xielder, yield
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/xielder/v/latest
- Size: 256 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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