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: 5 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 (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2025-08-05T02:39:26.000Z (11 months ago)
- Last Synced: 2025-08-19T00:21:29.323Z (10 months ago)
- Topics: xield, xielder, yield
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/xielder/v/latest
- Size: 257 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
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