7
7
// rdar://78109470
8
8
// UNSUPPORTED: back_deployment_runtime
9
9
10
- // Race condition
11
- // REQUIRES: rdar78033828
12
-
13
10
import _Concurrency
14
11
import StdlibUnittest
15
- import Dispatch
16
12
17
13
struct SomeError : Error , Equatable {
18
14
var value = Int . random ( in: 0 ..< 100 )
@@ -27,14 +23,34 @@ var tests = TestSuite("AsyncStream")
27
23
var fulfilled = false
28
24
}
29
25
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
+
30
46
tests. test ( " yield with no awaiting next " ) {
31
- let series = AsyncStream ( String . self) { continuation in
47
+ _ = AsyncStream ( String . self) { continuation in
32
48
continuation. yield ( " hello " )
33
49
}
34
50
}
35
51
36
52
tests. test ( " yield with no awaiting next throwing " ) {
37
- let series = AsyncThrowingStream ( String . self) { continuation in
53
+ _ = AsyncThrowingStream ( String . self) { continuation in
38
54
continuation. yield ( " hello " )
39
55
}
40
56
}
@@ -122,7 +138,7 @@ var tests = TestSuite("AsyncStream")
122
138
do {
123
139
expectEqual ( try await iterator. next ( ) , " hello " )
124
140
expectEqual ( try await iterator. next ( ) , " world " )
125
- try await iterator. next ( )
141
+ _ = try await iterator. next ( )
126
142
expectUnreachable ( " expected thrown error " )
127
143
} catch {
128
144
if let failure = error as? SomeError {
@@ -134,15 +150,15 @@ var tests = TestSuite("AsyncStream")
134
150
}
135
151
136
152
tests. test ( " yield with no awaiting next detached " ) {
137
- let series = AsyncStream ( String . self) { continuation in
153
+ _ = AsyncStream ( String . self) { continuation in
138
154
detach {
139
155
continuation. yield ( " hello " )
140
156
}
141
157
}
142
158
}
143
159
144
160
tests. test ( " yield with no awaiting next detached throwing " ) {
145
- let series = AsyncThrowingStream ( String . self) { continuation in
161
+ _ = AsyncThrowingStream ( String . self) { continuation in
146
162
detach {
147
163
continuation. yield ( " hello " )
148
164
}
@@ -246,7 +262,7 @@ var tests = TestSuite("AsyncStream")
246
262
do {
247
263
expectEqual ( try await iterator. next ( ) , " hello " )
248
264
expectEqual ( try await iterator. next ( ) , " world " )
249
- try await iterator. next ( )
265
+ _ = try await iterator. next ( )
250
266
expectUnreachable ( " expected thrown error " )
251
267
} catch {
252
268
if let failure = error as? SomeError {
@@ -337,7 +353,7 @@ var tests = TestSuite("AsyncStream")
337
353
let expectation = Expectation ( )
338
354
339
355
func scopedLifetime( _ expectation: Expectation ) {
340
- let series = AsyncStream ( String . self) { continuation in
356
+ _ = AsyncStream ( String . self) { continuation in
341
357
continuation. onTermination = { @Sendable _ in expectation. fulfilled = true }
342
358
}
343
359
}
@@ -351,7 +367,7 @@ var tests = TestSuite("AsyncStream")
351
367
let expectation = Expectation ( )
352
368
353
369
func scopedLifetime( _ expectation: Expectation ) {
354
- let series = AsyncStream ( String . self) { continuation in
370
+ _ = AsyncStream ( String . self) { continuation in
355
371
continuation. onTermination = { @Sendable _ in expectation. fulfilled = true }
356
372
continuation. finish ( )
357
373
}
@@ -366,7 +382,7 @@ var tests = TestSuite("AsyncStream")
366
382
let expectation = Expectation ( )
367
383
368
384
func scopedLifetime( _ expectation: Expectation ) {
369
- let series = AsyncStream ( String . self) { continuation in
385
+ _ = AsyncStream ( String . self) { continuation in
370
386
continuation. onTermination = { @Sendable terminal in
371
387
switch terminal {
372
388
case . cancelled:
@@ -386,7 +402,7 @@ var tests = TestSuite("AsyncStream")
386
402
let expectation = Expectation ( )
387
403
388
404
func scopedLifetime( _ expectation: Expectation ) {
389
- let series = AsyncThrowingStream ( String . self) { continuation in
405
+ _ = AsyncThrowingStream ( String . self) { continuation in
390
406
continuation. onTermination = { @Sendable terminal in
391
407
switch terminal {
392
408
case . cancelled:
0 commit comments