Decorator to convert a generator function to a :py:class:`~chainlink.ChainLink`

    :param generator_function: the generator function to convert
    :type generator_function: generator
    :param prime: advance the generator to the next/first yield
    :type prime: bool

    When used as a decorator, this function can also be called with and without keywords.

    .. code:: python

        @genlet
        def pingpong():
            "Chainlet that passes on its value"
            last = yield
            while True:
                last = yield last

        @genlet(prime=True)
        def produce():
            "Chainlet that produces a value"
            while True:
                yield time.time()

        @genlet(True)
        def read(iterable):
            "Chainlet that reads from an iterable"
            for item in iterable:
                yield item

def genlet(generator_function=None, prime=True):
    """
    Decorator to convert a generator function to a :py:class:`~chainlink.ChainLink`

    :param generator_function: the generator function to convert
    :type generator_function: generator
    :param prime: advance the generator to the next/first yield
    :type prime: bool

    When used as a decorator, this function can also be called with and without keywords.

    .. code:: python

        @genlet
        def pingpong():
            "Chainlet that passes on its value"
            last = yield
            while True:
                last = yield last

        @genlet(prime=True)
        def produce():
            "Chainlet that produces a value"
            while True:
                yield time.time()

        @genlet(True)
        def read(iterable):
            "Chainlet that reads from an iterable"
            for item in iterable:
                yield item
    """
    if generator_function is None:
        return GeneratorLink.wraplet(prime=prime)
    elif not callable(generator_function):
        return GeneratorLink.wraplet(prime=generator_function)
    return GeneratorLink.wraplet(prime=prime)(generator_function)