Skip to content

Instantly share code, notes, and snippets.

@jasdev
Created January 23, 2021 03:54
Show Gist options
  • Save jasdev/d6458b7ca8444beeaf036af56a8a2c0b to your computer and use it in GitHub Desktop.
Save jasdev/d6458b7ca8444beeaf036af56a8a2c0b to your computer and use it in GitHub Desktop.
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