aliyun-oss-react-native

OSSTaskCompletionSource.h 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 <Foundation/Foundation.h>
  11. NS_ASSUME_NONNULL_BEGIN
  12. @class OSSTask<ResultType>;
  13. /*!
  14. A OSSTaskCompletionSource represents the producer side of tasks.
  15. It is a task that also has methods for changing the state of the
  16. task by settings its completion values.
  17. */
  18. @interface OSSTaskCompletionSource<__covariant ResultType> : NSObject
  19. /*!
  20. Creates a new unfinished task.
  21. */
  22. + (instancetype)taskCompletionSource;
  23. /*!
  24. The task associated with this TaskCompletionSource.
  25. */
  26. @property (nonatomic, strong, readonly) OSSTask<ResultType> *task;
  27. /*!
  28. Completes the task by setting the result.
  29. Attempting to set this for a completed task will raise an exception.
  30. @param result The result of the task.
  31. */
  32. - (void)setResult:(nullable ResultType)result;
  33. /*!
  34. Completes the task by setting the error.
  35. Attempting to set this for a completed task will raise an exception.
  36. @param error The error for the task.
  37. */
  38. - (void)setError:(NSError *)error;
  39. /*!
  40. Completes the task by setting an exception.
  41. Attempting to set this for a completed task will raise an exception.
  42. @param exception The exception for the task.
  43. */
  44. - (void)setException:(NSException *)exception;
  45. /*!
  46. Completes the task by marking it as cancelled.
  47. Attempting to set this for a completed task will raise an exception.
  48. */
  49. - (void)cancel;
  50. /*!
  51. Sets the result of the task if it wasn't already completed.
  52. @returns whether the new value was set.
  53. */
  54. - (BOOL)trySetResult:(nullable ResultType)result;
  55. /*!
  56. Sets the error of the task if it wasn't already completed.
  57. @param error The error for the task.
  58. @returns whether the new value was set.
  59. */
  60. - (BOOL)trySetError:(NSError *)error;
  61. /*!
  62. Sets the exception of the task if it wasn't already completed.
  63. @param exception The exception for the task.
  64. @returns whether the new value was set.
  65. */
  66. - (BOOL)trySetException:(NSException *)exception;
  67. /*!
  68. Sets the cancellation state of the task if it wasn't already completed.
  69. @returns whether the new value was set.
  70. */
  71. - (BOOL)trySetCancelled;
  72. @end
  73. NS_ASSUME_NONNULL_END