UNPKG

@ginden/blinkstick-v2

Version:
26 lines 1.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.wrapGeneratorForAnimation = wrapGeneratorForAnimation; const AsyncGeneratorFunction = async function* () { }.constructor; const GeneratorFunction = function* () { }.constructor; /** * @summary Wrap a generator function into an object implementing Iterable or AsyncIterable. * 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