Skip to content

Commit

Permalink
Address PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
alessandroboron committed Sep 24, 2024
1 parent 218d74d commit 4445e45
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
17 changes: 15 additions & 2 deletions Core/Debouncer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,22 @@ import Foundation

/// A class that provides a debouncing mechanism.
public final class Debouncer {
private let runLoop: RunLoop
private let mode: RunLoop.Mode
private var timer: Timer?

public init() {}
/// Initializes a new instance of `Debouncer`.
///
/// - Parameters:
/// - runLoop: The `RunLoop` on which the debounced actions will be scheduled. Defaults to the current run loop.
///
/// - mode: The `RunLoop.Mode` in which the debounced actions will be scheduled. Defaults to `.default`.
///
/// Use `RunLoop.main` for UI-related actions to ensure they run on the main thread.
public init(runLoop: RunLoop = .current, mode: RunLoop.Mode = .default) {
self.runLoop = runLoop
self.mode = mode
}

/// Debounces the provided block of code, executing it after a specified time interval elapses.
/// - Parameters:
Expand All @@ -41,7 +54,7 @@ public final class Debouncer {
block()
})

RunLoop.main.add(timer, forMode: .common)
runLoop.add(timer, forMode: mode)
self.timer = timer
}

Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGo/TabViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ class TabViewController: UIViewController {

let syncService: DDGSyncing

private let daxDialogsDebouncer = Debouncer()
private let daxDialogsDebouncer = Debouncer(mode: .common)

public var url: URL? {
willSet {
Expand Down

0 comments on commit 4445e45

Please sign in to comment.