Commit b5c0b88a by Dima Bart

Add delay for polling handler.

parent e1ba41a2
...@@ -34,6 +34,8 @@ typedef BOOL (^BUYRequestOperationPollingHandler)(NSDictionary * _Nullable json, ...@@ -34,6 +34,8 @@ typedef BOOL (^BUYRequestOperationPollingHandler)(NSDictionary * _Nullable json,
@interface BUYRequestOperation : BUYOperation @interface BUYRequestOperation : BUYOperation
@property (assign, atomic) NSTimeInterval pollingInterval;
@property (strong, nonatomic, readonly, nonnull) NSURLSession *session; @property (strong, nonatomic, readonly, nonnull) NSURLSession *session;
@property (strong, nonatomic, readonly, nonnull) NSURLRequest *originalRequest; @property (strong, nonatomic, readonly, nonnull) NSURLRequest *originalRequest;
......
...@@ -73,6 +73,8 @@ typedef void (^BUYRequestJSONCompletion)(NSDictionary *json, NSHTTPURLResponse * ...@@ -73,6 +73,8 @@ typedef void (^BUYRequestJSONCompletion)(NSDictionary *json, NSHTTPURLResponse *
{ {
self = [super init]; self = [super init];
if (self) { if (self) {
self.pollingInterval = 0.3;
_session = session; _session = session;
_originalRequest = request; _originalRequest = request;
_completion = completion; _completion = completion;
...@@ -144,9 +146,16 @@ typedef void (^BUYRequestJSONCompletion)(NSDictionary *json, NSHTTPURLResponse * ...@@ -144,9 +146,16 @@ typedef void (^BUYRequestJSONCompletion)(NSDictionary *json, NSHTTPURLResponse *
* the polling process. * the polling process.
*/ */
if (self.pollingHandler && self.pollingHandler(json, response, error)) { if (self.pollingHandler && self.pollingHandler(json, response, error)) {
NSURLSessionDataTask *task = [self requestUsingPollingIfNeeded:request completion:completion];
self.runningTask = task; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(self.pollingInterval * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[task resume]; if (self.isCancelled) {
return;
}
NSURLSessionDataTask *task = [self requestUsingPollingIfNeeded:request completion:completion];
self.runningTask = task;
[task resume];
});
} else { } else {
completion(json, response, error); completion(json, response, error);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment