ObservationToken.swift 469 B

123456789101112131415161718
  1. // LoopFollow
  2. // ObservationToken.swift
  3. import Foundation
  4. /// The token received by an observe when subscribes to its subject. The observer can cancel observation, so the subject will remove it from its observers list.
  5. class ObservationToken {
  6. private let cancellationClosure: () -> Void
  7. init(cancellationClosure: @escaping () -> Void) {
  8. self.cancellationClosure = cancellationClosure
  9. }
  10. func cancel() {
  11. cancellationClosure()
  12. }
  13. }