Publishers.CollectByCount
let subject = PassthroughSubject<Int, Never>()
// Publishers.CollectByCount Publisher
Publishers.CollectByCount(upstream: subject, count: 2)
.sink(receiveCompletion: { completion in
switch completion {
case .failure:
print("Combine CollectByCount Error")
case .finished:
print("Combine CollectByCount Finish")
}
}, receiveValue: { value in
print("Combine CollectByCount : \(value)")
})
.store(in: &cancellables)
// collect Operator
subject
.collect(2)
.sink(receiveCompletion: { completion in
switch completion {
case .failure:
print("Combine CollectByCount Error")
case .finished:
print("Combine CollectByCount Finish")
}
}, receiveValue: { value in
print("Combine CollectByCount : \(value)")
})
.store(in: &cancellables)
// 1
subject.send(1)
// 2
subject.send(2)
// 3
subject.send(3)
// 4
subject.send(4)
// 5
subject.send(5)
// 6
subject.send(completion: .finished)
// Combine CollectByCount : [1, 2]
// Combine CollectByCount : [3, 4]
// Combine CollectByCount : [5]
// Combine CollectByCount FinishRxSwift
ReactiveSwift
μ°Έκ³
Last updated