Handle number of batches / last batch

This commit is contained in:
Alfonso Grillo
2023-01-25 12:35:51 +01:00
parent ef19527856
commit aafe903e99
5 changed files with 37 additions and 15 deletions
@@ -50,6 +50,10 @@ final class PollHistoryService: PollHistoryServiceProtocol {
func nextBatch() -> AnyPublisher<TimelinePollDetails, Error> {
currentBatchSubject?.eraseToAnyPublisher() ?? startPagination()
}
var hasNextBatch: Bool {
timeline.canPaginate(.backwards)
}
}
private extension PollHistoryService {
@@ -17,6 +17,15 @@
import Combine
final class MockPollHistoryService: PollHistoryServiceProtocol {
lazy var nextBatchPublisher: AnyPublisher<TimelinePollDetails, Error> = (activePollsData + pastPollsData)
.publisher
.setFailureType(to: Error.self)
.eraseToAnyPublisher()
func nextBatch() -> AnyPublisher<TimelinePollDetails, Error> {
nextBatchPublisher
}
var updatesPublisher: AnyPublisher<TimelinePollDetails, Never> = Empty().eraseToAnyPublisher()
var updates: AnyPublisher<TimelinePollDetails, Never> {
updatesPublisher
@@ -27,14 +36,7 @@ final class MockPollHistoryService: PollHistoryServiceProtocol {
pollErrorPublisher
}
lazy var nextBatchPublisher: AnyPublisher<TimelinePollDetails, Error> = (activePollsData + pastPollsData)
.publisher
.setFailureType(to: Error.self)
.eraseToAnyPublisher()
func nextBatch() -> AnyPublisher<TimelinePollDetails, Error> {
nextBatchPublisher
}
var hasNextBatch: Bool = true
}
private extension MockPollHistoryService {
@@ -27,4 +27,8 @@ protocol PollHistoryServiceProtocol {
/// Publishes errors regarding poll aggregations.
/// Note: `nextBatch()` will continue to publish new polls even if some poll isn't being aggregated correctly.
var pollErrors: AnyPublisher<Error, Never> { get }
/// Returns true every time the service can fetch another batch.
/// There is no guarantee the `nextBatch()` returned publisher will publish something anyway.
var hasNextBatch: Bool { get }
}