Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions Sources/ViewScope/ViewScope.docc/Extensions/ViewVisibilityScope.md

This file was deleted.

10 changes: 10 additions & 0 deletions Sources/ViewScope/ViewScope.docc/Extensions/VisibilityScope.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# ``VisibilityScope``

## Topics

### Adding Tasks

- ``task(priority:operation:)``
- ``task(id:priority:operation:)``
- ``task(executorPreference:priority:operation:)``
- ``task(id:executorPreference:priority:operation:)``
164 changes: 8 additions & 156 deletions Sources/ViewScope/VisibilityScope.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,207 +97,59 @@ 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.
/// - priority: The priority of the operation task.
/// - 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
Expand Down