Skip to content

Commit c4b666a

Browse files
authored
Do not create tasks when not bound (#4)
1 parent db35c2f commit c4b666a

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

Sources/ViewScope/VisibilityScope.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ public struct VisibilityScope {
103103
priority: TaskPriority = .userInitiated,
104104
operation: sending @escaping @isolated(any) () async -> Void
105105
) {
106+
guard bindCount > 0 else { return }
106107
enqueue(Task(priority: priority, operation: operation))
107108
}
108109

@@ -132,6 +133,7 @@ public struct VisibilityScope {
132133
priority: TaskPriority = .userInitiated,
133134
operation: sending @escaping () async -> Void
134135
) {
136+
guard bindCount > 0 else { return }
135137
enqueue(Task(executorPreference: taskExecutor, priority: priority, operation: operation))
136138
}
137139

@@ -149,6 +151,7 @@ public struct VisibilityScope {
149151
priority: TaskPriority = .userInitiated,
150152
operation: sending @escaping () async -> Void
151153
) {
154+
guard bindCount > 0 else { return }
152155
enqueue(Task(executorPreference: taskExecutor, priority: priority, operation: operation), with: id)
153156
}
154157

@@ -179,15 +182,13 @@ public struct VisibilityScope {
179182
private mutating func enqueue(
180183
_ task: Task<Void, Never>
181184
) {
182-
guard bindCount > 0 else { return }
183185
tasks.append(task)
184186
}
185187

186188
private mutating func enqueue(
187189
_ task: Task<Void, Never>,
188190
with id: some Hashable
189191
) {
190-
guard bindCount > 0 else { return }
191192
keyed[id]?.cancel()
192193
keyed[id] = task
193194
}

0 commit comments

Comments
 (0)