ObservationToken.swift 588 B

123456789101112131415161718192021222324
  1. //
  2. // ObservationToken.swift
  3. // nightguard
  4. //
  5. // Created by Florian Preknya on 1/30/19.
  6. // Copyright © 2019 private. All rights reserved.
  7. //
  8. import Foundation
  9. /// 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.
  10. class ObservationToken {
  11. private let cancellationClosure: () -> Void
  12. init(cancellationClosure: @escaping () -> Void) {
  13. self.cancellationClosure = cancellationClosure
  14. }
  15. func cancel() {
  16. cancellationClosure()
  17. }
  18. }