-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove subscriptions from
CurrentValueRelay
when cancelled (#2699)
* Remove subscription on cancel * Slight refactor * Small refactor Subscription keeps strong reference of `CurrentValueRelay` similar to `CurrentValueSubject` * Add subscription lifetime tests * Use weak subscriptions and remove inside send * Change relay implementation * For loop better * Move tests to StoreTests.swift * A few more locks and a Shared test. --------- Co-authored-by: Brandon Williams <mbrandonw@hey.com>
- Loading branch information
1 parent
87608bc
commit 5660c58
Showing
5 changed files
with
182 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
Tests/ComposableArchitectureTests/CurrentValueRelayTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#if DEBUG | ||
@preconcurrency import Combine | ||
@testable @preconcurrency import ComposableArchitecture | ||
import XCTest | ||
|
||
final class CurrentValueRelayTests: BaseTCATestCase { | ||
func testConcurrentSend() async { | ||
nonisolated(unsafe) let subject = CurrentValueRelay(0) | ||
let values = LockIsolated<Set<Int>>([]) | ||
let cancellable = subject.sink { (value: Int) in | ||
values.withValue { | ||
_ = $0.insert(value) | ||
} | ||
} | ||
|
||
await withTaskGroup(of: Void.self) { group in | ||
for index in 1...1_000 { | ||
group.addTask { | ||
subject.send(index) | ||
} | ||
} | ||
} | ||
|
||
XCTAssertEqual(values.value, Set(Array(0...1_000))) | ||
|
||
_ = cancellable | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters