@@ -580,70 +580,6 @@ func taskCreateFlags(
580
580
return bits
581
581
}
582
582
583
- // ==== Task Creation ----------------------------------------------------------
584
-
585
- @available ( SwiftStdlib 5 . 1 , * )
586
- extension Task where Failure == Never {
587
- #if SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
588
- @discardableResult
589
- @_alwaysEmitIntoClient
590
- @available ( * , unavailable, message: " Unavailable in task-to-thread concurrency model " )
591
- public init (
592
- priority: TaskPriority ? = nil ,
593
- @_inheritActorContext @_implicitSelfCapture operation: sending @escaping @isolated ( any) ( ) async -> Success
594
- ) {
595
- fatalError ( " Unavailable in task-to-thread concurrency model. " )
596
- }
597
- #else
598
- /// Runs the given nonthrowing operation asynchronously
599
- /// as part of a new top-level task on behalf of the current actor.
600
- ///
601
- /// Use this function when creating asynchronous work
602
- /// that operates on behalf of the synchronous function that calls it.
603
- /// Like `Task.detached(priority:operation:)`,
604
- /// this function creates a separate, top-level task.
605
- /// Unlike `Task.detached(priority:operation:)`,
606
- /// the task created by `Task.init(priority:operation:)`
607
- /// inherits the priority and actor context of the caller,
608
- /// so the operation is treated more like an asynchronous extension
609
- /// to the synchronous operation.
610
- ///
611
- /// You need to keep a reference to the task
612
- /// if you want to cancel it by calling the `Task.cancel()` method.
613
- /// Discarding your reference to a detached task
614
- /// doesn't implicitly cancel that task,
615
- /// it only makes it impossible for you to explicitly cancel the task.
616
- ///
617
- /// - Parameters:
618
- /// - priority: The priority of the task.
619
- /// Pass `nil` to use the priority from `Task.currentPriority`.
620
- /// - operation: The operation to perform.
621
- @discardableResult
622
- @_alwaysEmitIntoClient
623
- public init (
624
- priority: TaskPriority ? = nil ,
625
- @_inheritActorContext @_implicitSelfCapture operation: sending @escaping @isolated ( any) ( ) async -> Success
626
- ) {
627
- // Set up the job flags for a new task.
628
- let flags = taskCreateFlags (
629
- priority: priority, isChildTask: false , copyTaskLocals: true ,
630
- inheritContext: true , enqueueJob: true ,
631
- addPendingGroupTaskUnconditionally: false ,
632
- isDiscardingTask: false , isSynchronousStart: false )
633
-
634
- // Create the asynchronous task.
635
- let builtinSerialExecutor =
636
- unsafe Builtin. extractFunctionIsolation ( operation) ? . unownedExecutor. executor
637
-
638
- let ( task, _) = Builtin . createTask ( flags: flags,
639
- initialSerialExecutor: builtinSerialExecutor,
640
- operation: operation)
641
-
642
- self . _task = task
643
- }
644
- #endif
645
- }
646
-
647
583
@available ( SwiftStdlib 5 . 1 , * )
648
584
extension Task where Failure == Never {
649
585
#if SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
@@ -662,10 +598,10 @@ extension Task where Failure == Never {
662
598
@_alwaysEmitIntoClient
663
599
@available ( SwiftStdlib 5 . 1 , * )
664
600
public init ( // Task.init where Failure == Never (Embedded)
665
- name: String ? = nil , // ignored
601
+ name: String ? = nil ,
666
602
// TaskExecutor is unavailable in embedded
667
603
priority: TaskPriority ? = nil ,
668
- @_inheritActorContext @_implicitSelfCapture operation: sending @escaping ( ) async -> Success
604
+ @_inheritActorContext @_implicitSelfCapture operation: sending @escaping @ isolated ( any ) ( ) async -> Success
669
605
) {
670
606
// Set up the job flags for a new task.
671
607
let flags = taskCreateFlags (
@@ -678,9 +614,31 @@ extension Task where Failure == Never {
678
614
isDiscardingTask: false ,
679
615
isSynchronousStart: false )
680
616
681
- let ( task, _) = Builtin . createAsyncTask ( flags, operation)
617
+ let builtinSerialExecutor =
618
+ unsafe Builtin. extractFunctionIsolation ( operation) ? . unownedExecutor. executor
682
619
683
- self . _task = task
620
+ var task : Builtin . NativeObject ?
621
+ #if $BuiltinCreateAsyncTaskName
622
+ if let name {
623
+ task =
624
+ unsafe name. utf8CString . withUnsafeBufferPointer { nameBytes in
625
+ Builtin . createTask (
626
+ flags: flags,
627
+ initialSerialExecutor: builtinSerialExecutor,
628
+ taskName: nameBytes. baseAddress!. _rawValue,
629
+ operation: operation) . 0
630
+ }
631
+ } // let name
632
+ #endif // $BuiltinCreateAsyncTaskName
633
+
634
+ if task == nil {
635
+ task = Builtin . createTask (
636
+ flags: flags,
637
+ initialSerialExecutor: builtinSerialExecutor,
638
+ operation: operation) . 0
639
+ }
640
+
641
+ self . _task = task!
684
642
}
685
643
#else
686
644
/// Runs the given nonthrowing operation asynchronously
@@ -817,25 +775,28 @@ extension Task where Failure == Error {
817
775
818
776
var task : Builtin . NativeObject ?
819
777
#if $BuiltinCreateAsyncTaskName
820
- if let name {
821
- task =
822
- unsafe name. utf8CString . withUnsafeBufferPointer { nameBytes in
823
- Builtin . createTask (
824
- flags: flags,
825
- initialSerialExecutor: builtinSerialExecutor,
826
- taskName: nameBytes. baseAddress!. _rawValue,
827
- operation: operation) . 0
828
- }
829
- }
778
+ // if let name {
779
+ // task =
780
+ // unsafe name.utf8CString.withUnsafeBufferPointer { nameBytes in
781
+ // Builtin.createTask(
782
+ // flags: flags,
783
+ // initialSerialExecutor: builtinSerialExecutor,
784
+ // taskName: nameBytes.baseAddress!._rawValue,
785
+ // operation: operation).0
786
+ // }
787
+ // }
830
788
#endif
831
789
832
790
if task == nil {
833
791
// either no task name was set, or names are unsupported
834
- task = Builtin . createTask (
835
- flags: flags,
836
- initialSerialExecutor: builtinSerialExecutor,
837
- operation: operation) . 0
792
+ // task = Builtin.createTask(
793
+ // flags: flags,
794
+ // initialSerialExecutor: builtinSerialExecutor,
795
+ // operation: operation).0
838
796
}
797
+
798
+
799
+
839
800
840
801
self . _task = task!
841
802
}
0 commit comments