Proyectos de Subversion Iphone Microlearning

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
/**
2
 Copyright 2018 Google Inc. All rights reserved.
3
 
4
 Licensed under the Apache License, Version 2.0 (the "License");
5
 you may not use this file except in compliance with the License.
6
 You may obtain a copy of the License at:
7
 
8
 http://www.apache.org/licenses/LICENSE-2.0
9
 
10
 Unless required by applicable law or agreed to in writing, software
11
 distributed under the License is distributed on an "AS IS" BASIS,
12
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 See the License for the specific language governing permissions and
14
 limitations under the License.
15
 */
16
 
17
#import "FBLPromise.h"
18
 
19
NS_ASSUME_NONNULL_BEGIN
20
 
21
/** The default number of retry attempts is 1. */
22
FOUNDATION_EXTERN NSInteger const FBLPromiseRetryDefaultAttemptsCount NS_REFINED_FOR_SWIFT;
23
 
24
/** The default delay interval before making a retry attempt is 1.0 second. */
25
FOUNDATION_EXTERN NSTimeInterval const FBLPromiseRetryDefaultDelayInterval NS_REFINED_FOR_SWIFT;
26
 
27
@interface FBLPromise<Value>(RetryAdditions)
28
 
29
typedef id __nullable (^FBLPromiseRetryWorkBlock)(void) NS_SWIFT_UNAVAILABLE("");
30
typedef BOOL (^FBLPromiseRetryPredicateBlock)(NSInteger, NSError *) NS_SWIFT_UNAVAILABLE("");
31
 
32
/**
33
 Creates a pending promise that fulfills with the same value as the promise returned from `work`
34
 block, which executes asynchronously, or rejects with the same error after all retry attempts have
35
 been exhausted. Defaults to `FBLPromiseRetryDefaultAttemptsCount` attempt(s) on rejection where the
36
 `work` block is retried after a delay of `FBLPromiseRetryDefaultDelayInterval` second(s).
37
 
38
 @param work A block that executes asynchronously on the default queue and returns a value or an
39
             error used to resolve the promise.
40
 @return A new pending promise that fulfills with the same value as the promise returned from `work`
41
         block, or rejects with the same error after all retry attempts have been exhausted.
42
 */
43
+ (FBLPromise *)retry:(FBLPromiseRetryWorkBlock)work NS_SWIFT_UNAVAILABLE("");
44
 
45
/**
46
 Creates a pending promise that fulfills with the same value as the promise returned from `work`
47
 block, which executes asynchronously on the given `queue`, or rejects with the same error after all
48
 retry attempts have been exhausted. Defaults to `FBLPromiseRetryDefaultAttemptsCount` attempt(s) on
49
 rejection where the `work` block is retried on the given `queue` after a delay of
50
 `FBLPromiseRetryDefaultDelayInterval` second(s).
51
 
52
 @param queue A queue to invoke the `work` block on.
53
 @param work A block that executes asynchronously on the given `queue` and returns a value or an
54
             error used to resolve the promise.
55
 @return A new pending promise that fulfills with the same value as the promise returned from `work`
56
         block, or rejects with the same error after all retry attempts have been exhausted.
57
 */
58
+ (FBLPromise *)onQueue:(dispatch_queue_t)queue
59
                  retry:(FBLPromiseRetryWorkBlock)work NS_SWIFT_UNAVAILABLE("");
60
 
61
/**
62
 Creates a pending promise that fulfills with the same value as the promise returned from `work`
63
 block, which executes asynchronously, or rejects with the same error after all retry attempts have
64
 been exhausted.
65
 
66
 @param count Max number of retry attempts. The `work` block will be executed once if the specified
67
              count is less than or equal to zero.
68
 @param work A block that executes asynchronously on the default queue and returns a value or an
69
             error used to resolve the promise.
70
 @return A new pending promise that fulfills with the same value as the promise returned from `work`
71
         block, or rejects with the same error after all retry attempts have been exhausted.
72
 */
73
+ (FBLPromise *)attempts:(NSInteger)count
74
                   retry:(FBLPromiseRetryWorkBlock)work NS_SWIFT_UNAVAILABLE("");
75
 
76
/**
77
 Creates a pending promise that fulfills with the same value as the promise returned from `work`
78
 block, which executes asynchronously on the given `queue`, or rejects with the same error after all
79
 retry attempts have been exhausted.
80
 
81
 @param queue A queue to invoke the `work` block on.
82
 @param count Max number of retry attempts. The `work` block will be executed once if the specified
83
              count is less than or equal to zero.
84
 @param work A block that executes asynchronously on the given `queue` and returns a value or an
85
             error used to resolve the promise.
86
 @return A new pending promise that fulfills with the same value as the promise returned from `work`
87
         block, or rejects with the same error after all retry attempts have been exhausted.
88
 */
89
+ (FBLPromise *)onQueue:(dispatch_queue_t)queue
90
               attempts:(NSInteger)count
91
                  retry:(FBLPromiseRetryWorkBlock)work NS_SWIFT_UNAVAILABLE("");
92
 
93
/**
94
 Creates a pending promise that fulfills with the same value as the promise returned from `work`
95
 block, which executes asynchronously, or rejects with the same error after all retry attempts have
96
 been exhausted. On rejection, the `work` block is retried after the given delay `interval` and will
97
 continue to retry until the number of specified attempts have been exhausted or will bail early if
98
 the given condition is not met.
99
 
100
 @param count Max number of retry attempts. The `work` block will be executed once if the specified
101
              count is less than or equal to zero.
102
 @param interval Time to wait before the next retry attempt.
103
 @param predicate Condition to check before the next retry attempt. The predicate block provides the
104
                  the number of remaining retry attempts and the error that the promise was rejected
105
                  with.
106
 @param work A block that executes asynchronously on the default queue and returns a value or an
107
             error used to resolve the promise.
108
 @return A new pending promise that fulfills with the same value as the promise returned from `work`
109
         block, or rejects with the same error after all retry attempts have been exhausted or if
110
         the given condition is not met.
111
 */
112
+ (FBLPromise *)attempts:(NSInteger)count
113
                   delay:(NSTimeInterval)interval
114
               condition:(nullable FBLPromiseRetryPredicateBlock)predicate
115
                   retry:(FBLPromiseRetryWorkBlock)work NS_SWIFT_UNAVAILABLE("");
116
 
117
/**
118
 Creates a pending promise that fulfills with the same value as the promise returned from `work`
119
 block, which executes asynchronously on the given `queue`, or rejects with the same error after all
120
 retry attempts have been exhausted. On rejection, the `work` block is retried after the given
121
 delay `interval` and will continue to retry until the number of specified attempts have been
122
 exhausted or will bail early if the given condition is not met.
123
 
124
 @param queue A queue to invoke the `work` block on.
125
 @param count Max number of retry attempts. The `work` block will be executed once if the specified
126
              count is less than or equal to zero.
127
 @param interval Time to wait before the next retry attempt.
128
 @param predicate Condition to check before the next retry attempt. The predicate block provides the
129
                  the number of remaining retry attempts and the error that the promise was rejected
130
                  with.
131
 @param work A block that executes asynchronously on the given `queue` and returns a value or an
132
             error used to resolve the promise.
133
 @return A new pending promise that fulfills with the same value as the promise returned from `work`
134
         block, or rejects with the same error after all retry attempts have been exhausted or if
135
         the given condition is not met.
136
 */
137
+ (FBLPromise *)onQueue:(dispatch_queue_t)queue
138
               attempts:(NSInteger)count
139
                  delay:(NSTimeInterval)interval
140
              condition:(nullable FBLPromiseRetryPredicateBlock)predicate
141
                  retry:(FBLPromiseRetryWorkBlock)work NS_REFINED_FOR_SWIFT;
142
 
143
@end
144
 
145
/**
146
 Convenience dot-syntax wrappers for `FBLPromise+Retry` operators.
147
 Usage: FBLPromise.retry(^id { ... })
148
 */
149
@interface FBLPromise<Value>(DotSyntax_RetryAdditions)
150
 
151
+ (FBLPromise * (^)(FBLPromiseRetryWorkBlock))retry FBL_PROMISES_DOT_SYNTAX
152
    NS_SWIFT_UNAVAILABLE("");
153
+ (FBLPromise * (^)(dispatch_queue_t, FBLPromiseRetryWorkBlock))retryOn FBL_PROMISES_DOT_SYNTAX
154
    NS_SWIFT_UNAVAILABLE("");
155
+ (FBLPromise * (^)(NSInteger, NSTimeInterval, FBLPromiseRetryPredicateBlock __nullable,
156
                    FBLPromiseRetryWorkBlock))retryAgain FBL_PROMISES_DOT_SYNTAX
157
    NS_SWIFT_UNAVAILABLE("");
158
+ (FBLPromise * (^)(dispatch_queue_t, NSInteger, NSTimeInterval,
159
                    FBLPromiseRetryPredicateBlock __nullable,
160
                    FBLPromiseRetryWorkBlock))retryAgainOn FBL_PROMISES_DOT_SYNTAX
161
    NS_SWIFT_UNAVAILABLE("");
162
 
163
@end
164
 
165
NS_ASSUME_NONNULL_END