Cancellable.swift 645 B

1234567891011121314151617181920212223242526
  1. /// Protocol to define the opaque type returned from a request.
  2. public protocol Cancellable {
  3. /// A Boolean value stating whether a request is cancelled.
  4. var isCancelled: Bool { get }
  5. /// Cancels the represented request.
  6. func cancel()
  7. }
  8. internal class CancellableWrapper: Cancellable {
  9. internal var innerCancellable: Cancellable = SimpleCancellable()
  10. var isCancelled: Bool { return innerCancellable.isCancelled }
  11. internal func cancel() {
  12. innerCancellable.cancel()
  13. }
  14. }
  15. internal class SimpleCancellable: Cancellable {
  16. var isCancelled = false
  17. func cancel() {
  18. isCancelled = true
  19. }
  20. }