ObservationToken.swift 510 B

12345678910111213141516171819
  1. // LoopFollow
  2. // ObservationToken.swift
  3. // Created by Jon Fawcett on 2020-06-05.
  4. import Foundation
  5. /// 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.
  6. class ObservationToken {
  7. private let cancellationClosure: () -> Void
  8. init(cancellationClosure: @escaping () -> Void) {
  9. self.cancellationClosure = cancellationClosure
  10. }
  11. func cancel() {
  12. cancellationClosure()
  13. }
  14. }