Start a Deferred whose callBack arg is a deque of the accumulation
    of the values yielded from a_generator which is iterated over
    in batches the size of max_batch_size.

    It should be more efficient to iterate over the generator in
     batches and still provide enough speed for non-blocking execution.

    :param max_batch_size: The number of iterations of the generator
     to consume at a time.
    :param a_generator: An iterator which yields some not None values.
    :return: A Deferred to which the next callback will be called with
     the yielded contents of the generator function.

def batch_accumulate(max_batch_size, a_generator, cooperator=None):
    """
    Start a Deferred whose callBack arg is a deque of the accumulation
    of the values yielded from a_generator which is iterated over
    in batches the size of max_batch_size.

    It should be more efficient to iterate over the generator in
     batches and still provide enough speed for non-blocking execution.

    :param max_batch_size: The number of iterations of the generator
     to consume at a time.
    :param a_generator: An iterator which yields some not None values.
    :return: A Deferred to which the next callback will be called with
     the yielded contents of the generator function.
    """
    if cooperator:
        own_cooperate = cooperator.cooperate
    else:
        own_cooperate = cooperate

    spigot = ValueBucket()
    items = stream_tap((spigot,), a_generator)

    d = own_cooperate(i_batch(max_batch_size, items)).whenDone()
    d.addCallback(accumulation_handler, spigot)
    return d