diff --git a/Sources/ViewScope/ViewScope.docc/Extensions/ViewVisibilityScope.md b/Sources/ViewScope/ViewScope.docc/Extensions/ViewVisibilityScope.md deleted file mode 100644 index ca0a7a5..0000000 --- a/Sources/ViewScope/ViewScope.docc/Extensions/ViewVisibilityScope.md +++ /dev/null @@ -1,24 +0,0 @@ -# ``VisibilityScope`` - -## Topics - -### Tasks - -- ``task(name:priority:operation:)`` -- ``task(id:name:priority:operation:)`` -- ``task(name:executorPreference:priority:operation:)`` -- ``task(id:name:executorPreference:priority:operation:)`` - -### Detached Tasks - -- ``detachedTask(name:priority:operation:)`` -- ``detachedTask(id:name:priority:operation:)`` -- ``detachedTask(name:executorPreference:priority:operation:)`` -- ``detachedTask(id:name:executorPreference:priority:operation:)`` - -### Immediate Tasks - -- ``immediateTask(name:priority:executorPreference:operation:)`` -- ``immediateTask(id:name:priority:executorPreference:operation:)`` -- ``immediateDetachedTask(name:priority:executorPreference:operation:)`` -- ``immediateDetachedTask(id:name:priority:executorPreference:operation:)`` diff --git a/Sources/ViewScope/ViewScope.docc/Extensions/VisibilityScope.md b/Sources/ViewScope/ViewScope.docc/Extensions/VisibilityScope.md new file mode 100644 index 0000000..7eb71b1 --- /dev/null +++ b/Sources/ViewScope/ViewScope.docc/Extensions/VisibilityScope.md @@ -0,0 +1,10 @@ +# ``VisibilityScope`` + +## Topics + +### Adding Tasks + +- ``task(priority:operation:)`` +- ``task(id:priority:operation:)`` +- ``task(executorPreference:priority:operation:)`` +- ``task(id:executorPreference:priority:operation:)`` diff --git a/Sources/ViewScope/VisibilityScope.swift b/Sources/ViewScope/VisibilityScope.swift index 9be6b4f..2d48936 100644 --- a/Sources/ViewScope/VisibilityScope.swift +++ b/Sources/ViewScope/VisibilityScope.swift @@ -97,54 +97,47 @@ public struct VisibilityScope { /// Attach a task to the scope /// - Parameters: - /// - name: Human readable name of the task. /// - priority: The priority of the operation task. /// - operation: The operation to perform. public mutating func task( - name: String? = nil, - priority: TaskPriority? = nil, + priority: TaskPriority = .userInitiated, operation: sending @escaping @isolated(any) () async -> Void ) { - enqueue(Task(name: name, priority: priority, operation: operation)) + enqueue(Task(priority: priority, operation: operation)) } /// Attach a uniquely identified task to the scope /// - Parameters: /// - id: A uniqueness identifier. New tasks provided with this identifier will cancel this one. - /// - name: Human readable name of the task. /// - priority: The priority of the operation task. /// - operation: The operation to perform. public mutating func task( id: some Hashable, - name: String? = nil, - priority: TaskPriority? = nil, + priority: TaskPriority = .userInitiated, operation: sending @escaping @isolated(any) () async -> Void ) { guard bindCount > 0 else { return } - enqueue(Task(name: name, priority: priority, operation: operation), with: id) + enqueue(Task(priority: priority, operation: operation), with: id) } /// Attach a task to the scope /// - Parameters: - /// - name: Human readable name of the task. /// - taskExecutor: The task executor that the child task should be started on and keep using. /// Explicitly passing `nil` as the executor preference is equivalent to no preference, and effectively means to inherit the outer context’s executor preference. /// You can also pass the `globalConcurrentExecutor` global executor explicitly. /// - priority: The priority of the operation task. /// - operation: The operation to perform. public mutating func task( - name: String? = nil, executorPreference taskExecutor: (any TaskExecutor)?, - priority: TaskPriority? = nil, + priority: TaskPriority = .userInitiated, operation: sending @escaping () async -> Void ) { - enqueue(Task(name: name, executorPreference: taskExecutor, priority: priority, operation: operation)) + enqueue(Task(executorPreference: taskExecutor, priority: priority, operation: operation)) } /// Attach a uniquely identified task to the scope /// - Parameters: /// - id: A uniqueness identifier. New tasks provided with this identifier will cancel this one. - /// - name: Human readable name of the task. /// - taskExecutor: The task executor that the child task should be started on and keep using. /// Explicitly passing `nil` as the executor preference is equivalent to no preference, and effectively means to inherit the outer context’s executor preference. /// You can also pass the `globalConcurrentExecutor` global executor explicitly. @@ -152,152 +145,11 @@ public struct VisibilityScope { /// - operation: The operation to perform. public mutating func task( id: some Hashable, - name: String? = nil, executorPreference taskExecutor: (any TaskExecutor)?, - priority: TaskPriority? = nil, + priority: TaskPriority = .userInitiated, operation: sending @escaping () async -> Void ) { - enqueue(Task(name: name, executorPreference: taskExecutor, priority: priority, operation: operation), with: id) - } - - /// Attach a detached task to the scope - /// - Parameters: - /// - name: Human readable name of the task. - /// - priority: The priority of the operation task. - /// - operation: The operation to perform. - public mutating func detachedTask( - name: String? = nil, - priority: TaskPriority? = nil, - operation: sending @escaping @isolated(any) () async -> Void - ) { - enqueue(Task.detached(name: name, priority: priority, operation: operation)) - } - - /// Attached a detached task to the scope - /// - Parameters: - /// - name: Human readable name of the task. - /// - taskExecutor: The task executor that the child task should be started on and keep using. - /// Explicitly passing `nil` as the executor preference is equivalent to no preference, and effectively means to inherit the outer context’s executor preference. - /// You can also pass the `globalConcurrentExecutor` global executor explicitly. - /// - priority: The priority of the operation task. - /// - operation: The operation to perform. - public mutating func detachedTask( - name: String? = nil, - executorPreference taskExecutor: (any TaskExecutor)?, - priority: TaskPriority? = nil, - operation: sending @escaping () async -> Void - ) { - enqueue(Task.detached(name: name, executorPreference: taskExecutor, priority: priority, operation: operation)) - } - - /// Attach a uniquely identified detached task to the scope - /// - Parameters: - /// - id: A uniqueness identifier. New tasks provided with this identifier will cancel this one. - /// - name: Human readable name of the task. - /// - priority: The priority of the operation task. - /// - operation: The operation to perform. - public mutating func detachedTask( - id: some Hashable, - name: String? = nil, - priority: TaskPriority? = nil, - operation: sending @escaping @isolated(any) () async -> Void - ) { - enqueue(Task.detached(name: name, priority: priority, operation: operation), with: id) - } - - /// Attached a uniquely identified detached task to the scope - /// - Parameters: - /// - id: A uniqueness identifier. New tasks provided with this identifier will cancel this one. - /// - name: Human readable name of the task. - /// - taskExecutor: The task executor that the child task should be started on and keep using. - /// Explicitly passing `nil` as the executor preference is equivalent to no preference, and effectively means to inherit the outer context’s executor preference. - /// You can also pass the `globalConcurrentExecutor` global executor explicitly. - /// - priority: The priority of the operation task. - /// - operation: The operation to perform. - public mutating func detachedTask( - id: some Hashable, - name: String? = nil, - executorPreference taskExecutor: (any TaskExecutor)?, - priority: TaskPriority? = nil, - operation: sending @escaping () async -> Void - ) { - enqueue(Task.detached(name: name, executorPreference: taskExecutor, priority: priority, operation: operation), with: id) - } - - /// Attach an immediate task to the scope - /// - Parameters: - /// - name: The high-level human-readable name given for this task. - /// - priority: The priority of the task. Pass nil to use the `basePriority` of the current task (if there is one). - /// - taskExecutor: The task executor that the child task should be started on and keep using. - /// Explicitly passing `nil` as the executor preference is equivalent to no preference, and effectively means to inherit the outer context’s executor preference. - /// You can also pass the `globalConcurrentExecutor` global executor explicitly. - /// - operation: The operation to perform. - @available(macOS 26.0, macCatalyst 26.0, iOS 26.0, watchOS 26.0, tvOS 26.0, visionOS 26.0, *) - public mutating func immediateTask( - name: String? = nil, - priority: TaskPriority? = nil, - executorPreference taskExecutor: consuming (any TaskExecutor)? = nil, - operation: sending @escaping @isolated(any) () async -> Void - ) { - enqueue(Task.immediate(name: name, priority: priority, executorPreference: taskExecutor, operation: operation)) - } - - /// Attach a unquely identified immediate task to the scope - /// - Parameters: - /// - id: A uniqueness identifier. New tasks provided with this identifier will cancel this one. - /// - name: The high-level human-readable name given for this task. - /// - priority: The priority of the task. Pass nil to use the `basePriority` of the current task (if there is one). - /// - taskExecutor: The task executor that the child task should be started on and keep using. - /// Explicitly passing `nil` as the executor preference is equivalent to no preference, and effectively means to inherit the outer context’s executor preference. - /// You can also pass the `globalConcurrentExecutor` global executor explicitly. - /// - operation: The operation to perform. - @available(macOS 26.0, macCatalyst 26.0, iOS 26.0, watchOS 26.0, tvOS 26.0, visionOS 26.0, *) - public mutating func immediateTask( - id: some Hashable, - name: String? = nil, - priority: TaskPriority? = nil, - executorPreference taskExecutor: consuming (any TaskExecutor)? = nil, - operation: sending @escaping @isolated(any) () async -> Void - ) { - enqueue(Task.immediate(name: name, priority: priority, executorPreference: taskExecutor, operation: operation), with: id) - } - - /// Attach an immediate detached task to the scope - /// - Parameters: - /// - name: The high-level human-readable name given for this task. - /// - priority: The priority of the task. Pass nil to use the `basePriority` of the current task (if there is one). - /// - taskExecutor: The task executor that the child task should be started on and keep using. - /// Explicitly passing `nil` as the executor preference is equivalent to no preference, and effectively means to inherit the outer context’s executor preference. - /// You can also pass the `globalConcurrentExecutor` global executor explicitly. - /// - operation: The operation to perform. - @available(macOS 26.0, macCatalyst 26.0, iOS 26.0, watchOS 26.0, tvOS 26.0, visionOS 26.0, *) - public mutating func immediateDetachedTask( - name: String? = nil, - priority: TaskPriority? = nil, - executorPreference taskExecutor: consuming (any TaskExecutor)? = nil, - operation: sending @escaping @isolated(any) () async -> Void - ) { - enqueue(Task.immediateDetached(name: name, priority: priority, executorPreference: taskExecutor, operation: operation)) - } - - /// Attach a unquely identified immediate detached task to the scope - /// - Parameters: - /// - id: A uniqueness identifier. New tasks provided with this identifier will cancel this one. - /// - name: The high-level human-readable name given for this task. - /// - priority: The priority of the task. Pass nil to use the `basePriority` of the current task (if there is one). - /// - taskExecutor: The task executor that the child task should be started on and keep using. - /// Explicitly passing `nil` as the executor preference is equivalent to no preference, and effectively means to inherit the outer context’s executor preference. - /// You can also pass the `globalConcurrentExecutor` global executor explicitly. - /// - operation: The operation to perform. - @available(macOS 26.0, macCatalyst 26.0, iOS 26.0, watchOS 26.0, tvOS 26.0, visionOS 26.0, *) - public mutating func immediateDetachedTask( - id: some Hashable, - name: String? = nil, - priority: TaskPriority? = nil, - executorPreference taskExecutor: consuming (any TaskExecutor)? = nil, - operation: sending @escaping @isolated(any) () async -> Void - ) { - enqueue(Task.immediateDetached(name: name, priority: priority, executorPreference: taskExecutor, operation: operation), with: id) + enqueue(Task(executorPreference: taskExecutor, priority: priority, operation: operation), with: id) } // MARK: - Private