 
 import Foundation
 
+/// Receiver of crawler-related events.
 public protocol CrawlerDelegate: AnyObject {
-  func willVisit(url: URL)
-  func wordFound(at url: URL)
+
+  /// Called whenever the crawler is about to visit a new webpage.
+  func crawler(_ crawler: Crawler, willVisitUrl url: URL)
+
+  /// Called whenever the crawler finds the searched word in a webpage.
+  ///
+  /// - Note: This call is fired only (up to) one time per webpage, regardless
+  ///   of how many times the word is found in that webpage.
+  func crawler(_ crawler: Crawler, didFindWordAt url: URL)
+
+  /// Called once the crawler ends its execution.
+  func crawlerDidFinish(_ crawler: Crawler)
 }
 
 /// A web crawler.

  /// The urls of pages found during crawling, but yet to visit.
  var pagesToVisit: Set<URL>

  /// This callback is fired each time the crawler is about to visit a new
  /// webpage.
  let visitingCallback: ((URL) -> Void)?

  /// This callback is fired each time the parser finds `wordToSearch` in a
  /// web page (fired up to one time per page).
  let wordFoundCallback: (URL) -> Void

  /// The completion block called when the crawler ends its execution.
  let completion: (Int) -> Void

  /// The current `URLSessionDataTask`, if any.
  var currentTask: URLSessionDataTask?

  /// Immediately ends the crawling process.
  public func cancel() {
    currentTask?.cancel()
    delegate?.crawlerDidFinish(self)
  }

  /// Starts a new crawling cycle.
