Swift

image

image
image

image

image
image

image

image

image

image

image

image

image

image
image

Protect mutable state with Swift actors

image

Concurrency

Concurrency backword deply does not support! https://forums.swift.org/t/swift-concurrency-feedback-wanted/49336

@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
extension Task {

    /// An affordance to interact with an active task.
    ///
    /// You can use a task's handle to wait for its result or cancel the task.
    ///
    /// It isn't a programming error to discard a task's handle without awaiting or canceling the task.
    /// A task runs regardless of whether you still have its handle stored somewhere.
    /// However, if you discard a task's handle, you give up the ability
    /// to wait for that task's result or cancel the task.
    public struct Handle<Success, Failure> where Failure : Error {

        /// The task that this handle refers to.
        @available(*, deprecated, message: "Storing `Task` instances has been deprecated and will be removed soon.")
        public var task: Task { get }

        /// Wait for the task to complete, returning its result or throw an error.
        ///
        /// If the task hasn't completed, its priority increases to the
        /// priority of the current task. Note that this isn't as effective as
        /// creating the task with the correct priority.
        ///
        /// If the task throws an error, this method propogates that error.
        /// Tasks that respond to cancellation by throwing `Task.CancellationError`
        /// have that error propogated here upon cancellation.
        ///
        /// - Returns: The task's result.
        public func get() async throws -> Success

        /// Wait for the task to complete, returning its result or its error.
        ///
        /// If the task hasn't completed, its priority increases to the
        /// priority of the current task. Note that this isn't as effective as
        /// creating the task with the correct priority.
        ///
        /// If the task throws an error, this method propogates that error.
        /// Tasks that respond to cancellation by throwing `Task.CancellationError`
        /// have that error propogated here upon cancellation.
        ///
        /// - Returns: If the task succeeded, `.success`
        /// with the task's result as the associated value;
        /// otherwise, `.failure` with the error as the associated value.
        public func getResult() async -> Result<Success, Failure>

        /// Attempt to cancel the task.
        ///
        /// Whether this function has any effect is task-dependent.
        ///
        /// For a task to respect cancellation it must cooperatively check for it
        /// while running. Many tasks check for cancellation before beginning
        /// their "actual work"; however, this isn't a requirement nor is it guaranteed
        /// how and when tasks check for cancellation.
        public func cancel()
    }
}

  • async
  • asyncDetached
  • detach

_Concurrency interface

Use async/await with URLSession

image

Foundation

AttributedString

image
image
image
image
image
image
image
image

ResultBuilders

image

image