Files
Sportstime/SportsTime/Core/Services/SyncCancellationToken.swift
2026-02-10 18:15:36 -06:00

28 lines
651 B
Swift

//
// 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 }
}
}