Ingen beskrivning

AWSTaskCompletionSource.h 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 AWSTask<__covariant ResultType>;
  13. /*!
  14. A AWSTaskCompletionSource 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 AWSTaskCompletionSource<__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) AWSTask<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 NS_SWIFT_NAME(set(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 NS_SWIFT_NAME(set(error:));
  39. /*!
  40. Completes the task by marking it as cancelled.
  41. Attempting to set this for a completed task will raise an exception.
  42. */
  43. - (void)cancel;
  44. /*!
  45. Sets the result of the task if it wasn't already completed.
  46. @returns whether the new value was set.
  47. */
  48. - (BOOL)trySetResult:(nullable ResultType)result NS_SWIFT_NAME(trySet(result:));
  49. /*!
  50. Sets the error of the task if it wasn't already completed.
  51. @param error The error for the task.
  52. @returns whether the new value was set.
  53. */
  54. - (BOOL)trySetError:(NSError *)error NS_SWIFT_NAME(trySet(error:));
  55. /*!
  56. Sets the cancellation state of the task if it wasn't already completed.
  57. @returns whether the new value was set.
  58. */
  59. - (BOOL)trySetCancelled;
  60. @end
  61. NS_ASSUME_NONNULL_END