9
9
// UNSUPPORTED: back_deployment_runtime
10
10
// REQUIRES: concurrency_runtime
11
11
12
- final class InlineExecutor : SerialExecutor , CustomStringConvertible {
12
+ final class InlineExecutor_UnownedJob : SerialExecutor , CustomStringConvertible {
13
13
public func enqueue( _ job: UnownedJob ) {
14
14
job. runSynchronously ( on: self . asUnownedSerialExecutor ( ) )
15
15
}
16
+
17
+ var description : Swift . String {
18
+ " \( Self . self) () "
19
+ }
20
+ }
21
+ final class InlineExecutor_Job : SerialExecutor , CustomStringConvertible {
16
22
public func enqueue( _ job: __owned Job) {
17
23
job. runSynchronously ( on: self . asUnownedSerialExecutor ( ) )
18
24
}
25
+
26
+ var description : Swift . String {
27
+ " \( Self . self) () "
28
+ }
29
+ }
30
+
31
+ final class InlineExecutor_ExecutorJob : SerialExecutor , CustomStringConvertible {
19
32
public func enqueue( _ job: __owned ExecutorJob) {
20
33
job. runSynchronously ( on: self . asUnownedSerialExecutor ( ) )
21
34
}
22
35
23
36
var description : Swift . String {
24
- " InlineExecutor ()"
37
+ " \( Self . self ) () "
25
38
}
26
39
}
27
40
28
- let inlineExecutor = InlineExecutor ( )
41
+ let inlineExecutor_UnownedJob = InlineExecutor_UnownedJob ( )
42
+ let inlineExecutor_Job = InlineExecutor_Job ( )
43
+ let inlineExecutor_ExecutorJob = InlineExecutor_ExecutorJob ( )
29
44
30
45
actor Custom {
31
46
var count = 0
32
47
48
+ let selectedExecutor : any SerialExecutor
49
+
33
50
nonisolated var unownedExecutor : UnownedSerialExecutor {
34
- print ( " custom unownedExecutor " )
35
- return inlineExecutor. asUnownedSerialExecutor ( )
51
+ print ( " unownedExecutor: \( self . selectedExecutor) " )
52
+ return selectedExecutor. asUnownedSerialExecutor ( )
53
+ }
54
+
55
+ init ( selectedExecutor: some SerialExecutor ) {
56
+ self . selectedExecutor = selectedExecutor
36
57
}
37
58
38
59
func report( ) async {
@@ -44,20 +65,40 @@ actor Custom {
44
65
@available ( SwiftStdlib 5 . 1 , * )
45
66
@main struct Main {
46
67
static func main( ) async {
47
- print ( " begin " )
48
- let actor = Custom ( )
49
- await actor . report ( )
50
- await actor . report ( )
51
- await actor . report ( )
68
+ print ( " begin - unowned " )
69
+ let one = Custom ( selectedExecutor: inlineExecutor_UnownedJob)
70
+ await one. report ( )
71
+ await one. report ( )
72
+
73
+ print ( " begin - job " )
74
+ let two = Custom ( selectedExecutor: inlineExecutor_Job)
75
+ await two. report ( )
76
+ await two. report ( )
77
+
78
+ print ( " begin - executor job " )
79
+ let three = Custom ( selectedExecutor: inlineExecutor_ExecutorJob)
80
+ await three. report ( )
81
+ await three. report ( )
82
+
52
83
print ( " end " )
53
84
}
54
85
}
55
86
56
- // CHECK: begin
57
- // CHECK-NEXT: custom unownedExecutor
87
+ // CHECK: begin - unowned
88
+ // CHECK-NEXT: unownedExecutor: InlineExecutor_UnownedJob
89
+ // CHECK-NEXT: custom.count == 0
90
+ // CHECK-NEXT: unownedExecutor: InlineExecutor_UnownedJob
91
+ // CHECK-NEXT: custom.count == 1
92
+
93
+ // CHECK: begin - job
94
+ // CHECK-NEXT: unownedExecutor: InlineExecutor_Job
95
+ // CHECK-NEXT: custom.count == 0
96
+ // CHECK-NEXT: unownedExecutor: InlineExecutor_Job
97
+ // CHECK-NEXT: custom.count == 1
98
+
99
+ // CHECK: begin - executor job
100
+ // CHECK-NEXT: unownedExecutor: InlineExecutor_ExecutorJob
58
101
// CHECK-NEXT: custom.count == 0
59
- // CHECK-NEXT: custom unownedExecutor
102
+ // CHECK-NEXT: unownedExecutor: InlineExecutor_ExecutorJob
60
103
// CHECK-NEXT: custom.count == 1
61
- // CHECK-NEXT: custom unownedExecutor
62
- // CHECK-NEXT: custom.count == 2
63
104
// CHECK-NEXT: end
0 commit comments