//
//  SyncCancellationToken.swift
//  SportsTime
//
//  Cancellation support for long-running sync operations.
//

import Foundation
import os

/// Protocol for cancellation tokens checked between sync pages
protocol SyncCancellationToken: Sendable {
    nonisolated var isCancelled: Bool { get }
}

/// Concrete cancellation token for background tasks
final class BackgroundTaskCancellationToken: SyncCancellationToken, @unchecked Sendable {
    private let lock = OSAllocatedUnfairLock(initialState: false)

    nonisolated var isCancelled: Bool {
        lock.withLock { $0 }
    }

    func cancel() {
        lock.withLock { $0 = true }
    }
}
