---
title: "buffer(size:prefetch:whenFull:)"
framework: combine
role: symbol
role_heading: Instance Method
path: "combine/publisher/buffer(size:prefetch:whenfull:)"
---

# buffer(size:prefetch:whenFull:)

Buffers elements received from an upstream publisher.

## Declaration

```swift
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

Processing Published Elements with Subscribers

## Return Value

Return Value A publisher that buffers elements received from an upstream publisher.

## Discussion

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

- [Publishers.PrefetchStrategy](combine/publishers/prefetchstrategy.md)
- [Publishers.BufferingStrategy](combine/publishers/bufferingstrategy.md)
