Skip to content

Commit 88cfef7

Browse files
committed
Add cancel
1 parent 41e160b commit 88cfef7

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

Tool/Sources/DebounceFunction/DebounceFunction.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ public actor DebounceFunction<T> {
1111
self.block = block
1212
}
1313

14+
public func cancel() {
15+
task?.cancel()
16+
}
17+
1418
public func callAsFunction(_ t: T) async {
1519
task?.cancel()
1620
task = Task { [block, duration] in
@@ -29,6 +33,10 @@ public actor DebounceRunner {
2933
self.duration = duration
3034
}
3135

36+
public func cancel() {
37+
task?.cancel()
38+
}
39+
3240
public func debounce(_ block: @escaping () async -> Void) {
3341
task?.cancel()
3442
task = Task { [duration] in
@@ -37,3 +45,4 @@ public actor DebounceRunner {
3745
}
3846
}
3947
}
48+

0 commit comments

Comments
 (0)