Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Buffered subscribing, batched outputting in Combine.
extension Sequence where Element: Publisher {
func bufferedSubscribe(by size: Int) -> AnyPublisher<[Element.Output], Element.Failure> {
publisher
.flatMap(maxPublishers: .max(size)) { $0 }
.collect(size)
.eraseToAnyPublisher()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment