@ginden/blinkstick-v2
Version:
Improved Blickstick API for Node.js
25 lines • 956 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.wrapGeneratorForAnimation = wrapGeneratorForAnimation;
const AsyncGeneratorFunction = async function* () { }.constructor;
const GeneratorFunction = function* () { }.constructor;
/**
* A common mistake is to pass a generator object to a function that expects an iterable.
* While generators are iterable, they behave very differently from other iterables.
* In particular, they are not reusable - you can iterate over them only once, unlike arrays or sets.
* @category Utils
*/
function wrapGeneratorForAnimation(v) {
if (v instanceof AsyncGeneratorFunction) {
return {
[Symbol.asyncIterator]: v,
};
}
else if (v instanceof GeneratorFunction) {
return {
[Symbol.iterator]: v,
};
}
throw new Error('Invalid generator function');
}
//# sourceMappingURL=wrap-generator-function-in-object.js.map