Contents

buffer(size:prefetch:whenFull:)

Buffers elements received from an upstream publisher.

Declaration

func buffer(size: Int, prefetch: Publishers.PrefetchStrategy, whenFull: Publishers.BufferingStrategy<Self.Failure>) -> Publishers.Buffer<Self>

Parameters

  • size:

    The maximum number of elements to store.

  • prefetch:

    The strategy to initially populate the buffer.

  • whenFull:

    The action to take when the buffer becomes full.

Mentioned in

Return Value

A publisher that buffers elements received from an upstream publisher.

Discussion

Use buffer(size:prefetch:whenFull:) to collect a specific number of elements from an upstream publisher before republishing them to the downstream subscriber according to the Publishers.BufferingStrategy and Publishers.PrefetchStrategy strategy you specify.

If the publisher completes before reaching the size threshold, it buffers the elements and publishes them downstream prior to completion.

See Also

Buffering elements