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
+ public func enqueue( _ job: UnownedJob ) {
14
+ job. runSynchronously ( on: self . asUnownedSerialExecutor ( ) )
15
+ }
16
+
17
+ var description : Swift . String {
18
+ " \( Self . self) () "
19
+ }
20
+ }
21
+ final class InlineExecutor_Job : SerialExecutor , CustomStringConvertible {
22
+ public func enqueue( _ job: __owned Job) {
23
+ job. runSynchronously ( on: self . asUnownedSerialExecutor ( ) )
24
+ }
25
+
26
+ var description : Swift . String {
27
+ " \( Self . self) () "
28
+ }
29
+ }
30
+
31
+ final class InlineExecutor_ExecutorJob : SerialExecutor , CustomStringConvertible {
13
32
public func enqueue( _ job: __owned ExecutorJob) {
14
33
job. runSynchronously ( on: self . asUnownedSerialExecutor ( ) )
15
34
}
16
35
17
36
var description : Swift . String {
18
- " InlineExecutor ()"
37
+ " \( Self . self ) () "
19
38
}
20
39
}
21
40
22
- let inlineExecutor = InlineExecutor ( )
41
+ let inlineExecutor_UnownedJob = InlineExecutor_UnownedJob ( )
42
+ let inlineExecutor_Job = InlineExecutor_Job ( )
43
+ let inlineExecutor_ExecutorJob = InlineExecutor_ExecutorJob ( )
23
44
24
45
actor Custom {
25
46
var count = 0
26
47
48
+ let selectedExecutor : any SerialExecutor
49
+
27
50
nonisolated var unownedExecutor : UnownedSerialExecutor {
28
- print ( " custom unownedExecutor " )
29
- return inlineExecutor. asUnownedSerialExecutor ( )
51
+ print ( " unownedExecutor: \( self . selectedExecutor) " )
52
+ return selectedExecutor. asUnownedSerialExecutor ( )
53
+ }
54
+
55
+ init ( selectedExecutor: some SerialExecutor ) {
56
+ self . selectedExecutor = selectedExecutor
30
57
}
31
58
32
59
func report( ) async {
@@ -38,20 +65,40 @@ actor Custom {
38
65
@available ( SwiftStdlib 5 . 1 , * )
39
66
@main struct Main {
40
67
static func main( ) async {
41
- print ( " begin " )
42
- let actor = Custom ( )
43
- await actor . report ( )
44
- await actor . report ( )
45
- 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
+
46
83
print ( " end " )
47
84
}
48
85
}
49
86
50
- // CHECK: begin
51
- // 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
52
101
// CHECK-NEXT: custom.count == 0
53
- // CHECK-NEXT: custom unownedExecutor
102
+ // CHECK-NEXT: unownedExecutor: InlineExecutor_ExecutorJob
54
103
// CHECK-NEXT: custom.count == 1
55
- // CHECK-NEXT: custom unownedExecutor
56
- // CHECK-NEXT: custom.count == 2
57
104
// CHECK-NEXT: end
0 commit comments