xielder
v0.0.4
Published
A yield expression is only allowed in a generator body. But you can xield anywhere.
Downloads
1
Readme
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 xield
ing:
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