77// rdar://78109470
88// UNSUPPORTED: back_deployment_runtime
99
10- // Race condition
11- // REQUIRES: rdar78033828
12-
1310import _Concurrency
1411import StdlibUnittest
15- import Dispatch
1612
1713struct SomeError : Error , Equatable {
1814 var value = Int . random ( in: 0 ..< 100 )
@@ -27,14 +23,34 @@ var tests = TestSuite("AsyncStream")
2723 var fulfilled = false
2824 }
2925
26+ tests. test ( " factory method " ) {
27+ let ( stream, continuation) = AsyncStream . makeStream ( of: String . self)
28+ continuation. yield ( " hello " )
29+
30+ var iterator = stream. makeAsyncIterator ( )
31+ expectEqual ( await iterator. next ( ) , " hello " )
32+ }
33+
34+ tests. test ( " throwing factory method " ) {
35+ let ( stream, continuation) = AsyncThrowingStream . makeStream ( of: String . self, throwing: Error . self)
36+ continuation. yield ( " hello " )
37+
38+ var iterator = stream. makeAsyncIterator ( )
39+ do {
40+ expectEqual ( try await iterator. next ( ) , " hello " )
41+ } catch {
42+ expectUnreachable ( " unexpected error thrown " )
43+ }
44+ }
45+
3046 tests. test ( " yield with no awaiting next " ) {
31- let series = AsyncStream ( String . self) { continuation in
47+ _ = AsyncStream ( String . self) { continuation in
3248 continuation. yield ( " hello " )
3349 }
3450 }
3551
3652 tests. test ( " yield with no awaiting next throwing " ) {
37- let series = AsyncThrowingStream ( String . self) { continuation in
53+ _ = AsyncThrowingStream ( String . self) { continuation in
3854 continuation. yield ( " hello " )
3955 }
4056 }
@@ -122,7 +138,7 @@ var tests = TestSuite("AsyncStream")
122138 do {
123139 expectEqual ( try await iterator. next ( ) , " hello " )
124140 expectEqual ( try await iterator. next ( ) , " world " )
125- try await iterator. next ( )
141+ _ = try await iterator. next ( )
126142 expectUnreachable ( " expected thrown error " )
127143 } catch {
128144 if let failure = error as? SomeError {
@@ -134,15 +150,15 @@ var tests = TestSuite("AsyncStream")
134150 }
135151
136152 tests. test ( " yield with no awaiting next detached " ) {
137- let series = AsyncStream ( String . self) { continuation in
153+ _ = AsyncStream ( String . self) { continuation in
138154 detach {
139155 continuation. yield ( " hello " )
140156 }
141157 }
142158 }
143159
144160 tests. test ( " yield with no awaiting next detached throwing " ) {
145- let series = AsyncThrowingStream ( String . self) { continuation in
161+ _ = AsyncThrowingStream ( String . self) { continuation in
146162 detach {
147163 continuation. yield ( " hello " )
148164 }
@@ -246,7 +262,7 @@ var tests = TestSuite("AsyncStream")
246262 do {
247263 expectEqual ( try await iterator. next ( ) , " hello " )
248264 expectEqual ( try await iterator. next ( ) , " world " )
249- try await iterator. next ( )
265+ _ = try await iterator. next ( )
250266 expectUnreachable ( " expected thrown error " )
251267 } catch {
252268 if let failure = error as? SomeError {
@@ -337,7 +353,7 @@ var tests = TestSuite("AsyncStream")
337353 let expectation = Expectation ( )
338354
339355 func scopedLifetime( _ expectation: Expectation ) {
340- let series = AsyncStream ( String . self) { continuation in
356+ _ = AsyncStream ( String . self) { continuation in
341357 continuation. onTermination = { @Sendable _ in expectation. fulfilled = true }
342358 }
343359 }
@@ -351,7 +367,7 @@ var tests = TestSuite("AsyncStream")
351367 let expectation = Expectation ( )
352368
353369 func scopedLifetime( _ expectation: Expectation ) {
354- let series = AsyncStream ( String . self) { continuation in
370+ _ = AsyncStream ( String . self) { continuation in
355371 continuation. onTermination = { @Sendable _ in expectation. fulfilled = true }
356372 continuation. finish ( )
357373 }
@@ -366,7 +382,7 @@ var tests = TestSuite("AsyncStream")
366382 let expectation = Expectation ( )
367383
368384 func scopedLifetime( _ expectation: Expectation ) {
369- let series = AsyncStream ( String . self) { continuation in
385+ _ = AsyncStream ( String . self) { continuation in
370386 continuation. onTermination = { @Sendable terminal in
371387 switch terminal {
372388 case . cancelled:
@@ -386,7 +402,7 @@ var tests = TestSuite("AsyncStream")
386402 let expectation = Expectation ( )
387403
388404 func scopedLifetime( _ expectation: Expectation ) {
389- let series = AsyncThrowingStream ( String . self) { continuation in
405+ _ = AsyncThrowingStream ( String . self) { continuation in
390406 continuation. onTermination = { @Sendable terminal in
391407 switch terminal {
392408 case . cancelled:
0 commit comments