Skip to content

Commit b3f48b8

Browse files
mbrandonwp4checo
authored andcommitted
Use @_spi to test more internals in release. (#1456)
(cherry picked from commit 16b47009b9ac72f4d82e16edf242adca8a9380d2) # Conflicts: # Sources/ComposableArchitecture/Effects/Cancellation.swift # Sources/ComposableArchitecture/Internal/TaskCancellableValue.swift # Sources/ComposableArchitecture/Store.swift # Tests/ComposableArchitectureTests/EffectCancellationTests.swift # Tests/ComposableArchitectureTests/StoreTests.swift # Tests/ComposableArchitectureTests/TaskCancellationTests.swift
1 parent 487509e commit b3f48b8

File tree

14 files changed

+1933
-1955
lines changed

14 files changed

+1933
-1955
lines changed

Sources/ComposableArchitecture/Effects/Cancellation.swift

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ extension Effect {
4646
return Self(
4747
operation: .producer(
4848
SignalProducer.deferred { () -> SignalProducer<Action, Failure> in
49-
cancellablesLock.lock()
50-
defer { cancellablesLock.unlock() }
49+
_cancellablesLock.lock()
50+
defer { _cancellablesLock.unlock() }
5151

52-
let id = CancelToken(id: id)
52+
let id = _CancelToken(id: id)
5353
if cancelInFlight {
54-
cancellationCancellables[id]?.forEach { $0.dispose() }
54+
_cancellationCancellables[id]?.forEach { $0.dispose() }
5555
}
5656

5757
let subject = Signal<Action, Failure>.pipe()
@@ -66,17 +66,17 @@ extension Effect {
6666
.start(subject.input)
6767
var cancellationDisposable: AnyDisposable!
6868
cancellationDisposable = AnyDisposable {
69-
cancellablesLock.sync {
69+
_cancellablesLock.sync {
7070
subject.input.sendCompleted()
7171
disposable.dispose()
72-
cancellationCancellables[id]?.remove(cancellationDisposable)
73-
if cancellationCancellables[id]?.isEmpty == .some(true) {
74-
cancellationCancellables[id] = nil
72+
_cancellationCancellables[id]?.remove(cancellationDisposable)
73+
if _cancellationCancellables[id]?.isEmpty == .some(true) {
74+
_cancellationCancellables[id] = nil
7575
}
7676
}
7777
}
7878

79-
cancellationCancellables[id, default: []].insert(
79+
_cancellationCancellables[id, default: []].insert(
8080
cancellationDisposable
8181
)
8282

@@ -124,8 +124,8 @@ extension Effect {
124124
/// identifier.
125125
public static func cancel(id: AnyHashable) -> Self {
126126
.fireAndForget {
127-
cancellablesLock.sync {
128-
cancellationCancellables[.init(id: id)]?.forEach { $0.dispose() }
127+
_cancellablesLock.sync {
128+
_cancellationCancellables[.init(id: id)]?.forEach { $0.dispose() }
129129
}
130130
}
131131
}
@@ -208,21 +208,21 @@ public func withTaskCancellation<T: Sendable>(
208208
cancelInFlight: Bool = false,
209209
operation: @Sendable @escaping () async throws -> T
210210
) async rethrows -> T {
211-
let id = CancelToken(id: id)
212-
let (cancellable, task) = cancellablesLock.sync { () -> (AnyDisposable, Task<T, Error>) in
211+
let id = _CancelToken(id: id)
212+
let (cancellable, task) = _cancellablesLock.sync { () -> (AnyDisposable, Task<T, Error>) in
213213
if cancelInFlight {
214-
cancellationCancellables[id]?.forEach { $0.dispose() }
214+
_cancellationCancellables[id]?.forEach { $0.dispose() }
215215
}
216216
let task = Task { try await operation() }
217217
let cancellable = AnyDisposable { task.cancel() }
218-
cancellationCancellables[id, default: []].insert(cancellable)
218+
_cancellationCancellables[id, default: []].insert(cancellable)
219219
return (cancellable, task)
220220
}
221221
defer {
222-
cancellablesLock.sync {
223-
cancellationCancellables[id]?.remove(cancellable)
224-
if cancellationCancellables[id]?.isEmpty == .some(true) {
225-
cancellationCancellables[id] = nil
222+
_cancellablesLock.sync {
223+
_cancellationCancellables[id]?.remove(cancellable)
224+
if _cancellationCancellables[id]?.isEmpty == .some(true) {
225+
_cancellationCancellables[id] = nil
226226
}
227227
}
228228
}
@@ -262,7 +262,7 @@ extension Task where Success == Never, Failure == Never {
262262
///
263263
/// - Parameter id: An identifier.
264264
public static func cancel<ID: Hashable & Sendable>(id: ID) {
265-
cancellablesLock.sync { cancellationCancellables[.init(id: id)]?.forEach { $0.dispose() } }
265+
_cancellablesLock.sync { _cancellationCancellables[.init(id: id)]?.forEach { $0.dispose() } }
266266
}
267267

268268
/// Cancel any currently in-flight operation with the given identifier.
@@ -276,18 +276,18 @@ extension Task where Success == Never, Failure == Never {
276276
}
277277
}
278278

279-
struct CancelToken: Hashable {
279+
@_spi(Internals) public struct _CancelToken: Hashable {
280280
let id: AnyHashable
281281
let discriminator: ObjectIdentifier
282282

283-
init(id: AnyHashable) {
283+
public init(id: AnyHashable) {
284284
self.id = id
285285
self.discriminator = ObjectIdentifier(type(of: id.base))
286286
}
287287
}
288288

289-
var cancellationCancellables: [CancelToken: Set<AnyDisposable>] = [:]
290-
let cancellablesLock = NSRecursiveLock()
289+
@_spi(Internals) public var _cancellationCancellables: [_CancelToken: Set<AnyDisposable>] = [:]
290+
@_spi(Internals) public let _cancellablesLock = NSRecursiveLock()
291291

292292
@rethrows
293293
private protocol _ErrorMechanism {

0 commit comments

Comments
 (0)