OSSCancellationTokenSource.m 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Copyright (c) 2014, Facebook, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the BSD-style license found in the
  6. * LICENSE file in the root directory of this source tree. An additional grant
  7. * of patent rights can be found in the PATENTS file in the same directory.
  8. *
  9. */
  10. #import "OSSCancellationTokenSource.h"
  11. #import "OSSCancellationToken.h"
  12. NS_ASSUME_NONNULL_BEGIN
  13. @interface OSSCancellationToken (OSSCancellationTokenSource)
  14. - (void)cancel;
  15. - (void)cancelAfterDelay:(int)millis;
  16. - (void)dispose;
  17. - (void)throwIfDisposed;
  18. @end
  19. @implementation OSSCancellationTokenSource
  20. #pragma mark - Initializer
  21. - (instancetype)init {
  22. self = [super init];
  23. if (!self) return self;
  24. _token = [OSSCancellationToken new];
  25. return self;
  26. }
  27. + (instancetype)cancellationTokenSource {
  28. return [OSSCancellationTokenSource new];
  29. }
  30. #pragma mark - Custom Setters/Getters
  31. - (BOOL)isCancellationRequested {
  32. return _token.isCancellationRequested;
  33. }
  34. - (void)cancel {
  35. [_token cancel];
  36. }
  37. - (void)cancelAfterDelay:(int)millis {
  38. [_token cancelAfterDelay:millis];
  39. }
  40. - (void)dispose {
  41. [_token dispose];
  42. }
  43. @end
  44. NS_ASSUME_NONNULL_END