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