Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MBP-4700 Pagination 트리거 로직을 개선하고 Secion 단위가 아닌 List 단위로 콜백받을 수 있도록 변경해요. #43

Closed
wants to merge 10 commits into from
35 changes: 35 additions & 0 deletions Sources/KarrotListKit/NextBatchTrigger/NextBatchContext.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// Copyright (c) 2024 Danggeun Market Inc.
//

import Foundation

/// Manages the context for fetching the next batch of data.
public class NextBatchContext {

/// Represents the current state of the batch fetching process.
public enum State {
/// Indicates that the fetching process is currently ongoing.
case fetching
/// Indicates that the fetching process has been completed.
case completed
}

/// The current state of the batch fetching process.
private(set) var state: State = .completed

/// A lock to ensure thread safety when updating the state.
private let lock = NSLock()
jaxtynSong marked this conversation as resolved.
Show resolved Hide resolved

/// Begins the batch fetching process by setting the state to `fetching`.
func beginBatchFetching() {
lock.lock(); defer { self.lock.unlock() }
state = .fetching
}

/// Completes the batch fetching process by setting the state to `completed`.
public func completeBatchFetching() {
lock.lock(); defer { self.lock.unlock() }
state = .completed
}
}