File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
Tests/ComposableArchitectureTests Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change 2525
2626 _ = cancellable
2727 }
28+
29+ func testConcurrentSendAndReceive( ) async {
30+ nonisolated ( unsafe) let subject = CurrentValueRelay ( 0 )
31+ let values = LockIsolated < Set < Int > > ( [ ] )
32+ let cancellable = subject. sink { ( value: Int ) in
33+ values. withValue {
34+ _ = $0. insert ( value)
35+ }
36+ }
37+
38+ let receives = Task . detached { @Sendable in
39+ for await _ in subject. values { }
40+ }
41+
42+ await withTaskGroup ( of: Void . self) { group in
43+ for index in 1 ... 1_000 {
44+ group. addTask { @Sendable in
45+ subject. send ( index)
46+ }
47+ }
48+ }
49+
50+ receives. cancel ( )
51+ _ = await receives. value
52+
53+ XCTAssertEqual ( values. value, Set ( Array ( 0 ... 1_000 ) ) )
54+
55+ _ = cancellable
56+ }
2857 }
2958#endif
You can’t perform that action at this time.
0 commit comments