File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed
stdlib/public/Concurrency Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -579,6 +579,7 @@ public func runAsyncAndBlock(_ asyncFun: @escaping () async -> ())
579
579
public func _async MainDrainQueue( ) -> Never
580
580
581
581
public func _runAsyncMain( _ asyncFun: @escaping ( ) async throws -> ( ) ) {
582
+ #if os(Windows)
582
583
Task . runDetached {
583
584
do {
584
585
try await asyncFun ( )
@@ -587,6 +588,21 @@ public func _runAsyncMain(_ asyncFun: @escaping () async throws -> ()) {
587
588
_errorInMain ( error)
588
589
}
589
590
}
591
+ #else
592
+ @MainActor @concurrent
593
+ func _doMain( _ asyncFun: @escaping ( ) async throws -> ( ) ) async {
594
+ do {
595
+ try await asyncFun ( )
596
+ } catch {
597
+ _errorInMain ( error)
598
+ }
599
+ }
600
+
601
+ Task . runDetached {
602
+ await _doMain ( asyncFun)
603
+ exit ( 0 )
604
+ }
605
+ #endif
590
606
_asyncMainDrainQueue ( )
591
607
}
592
608
Original file line number Diff line number Diff line change @@ -66,6 +66,8 @@ actor A {
66
66
67
67
// CHECK: starting
68
68
// CHECK-NOT: ERROR
69
+ // CHECK: Hello from the main function
70
+ // CHECK-NOT: ERROR
69
71
// CHECK: hello from main actor!
70
72
// CHECK-NOT: ERROR
71
73
// CHECK: on actor instance's queue
@@ -77,6 +79,11 @@ actor A {
77
79
@main struct RunIt {
78
80
static func main( ) async {
79
81
print ( " starting " )
82
+ if checkIfMainQueue ( expectedAnswer: true ) {
83
+ print ( " Hello from the main function " )
84
+ } else {
85
+ print ( " ERROR: not on the main queue " )
86
+ }
80
87
let result = await someFunc ( )
81
88
print ( " finished with return counter = \( result) " )
82
89
}
You can’t perform that action at this time.
0 commit comments