Commit b5c0b88a by Dima Bart

Add delay for polling handler.

parent e1ba41a2
......@@ -34,6 +34,8 @@ typedef BOOL (^BUYRequestOperationPollingHandler)(NSDictionary * _Nullable json,
@interface BUYRequestOperation : BUYOperation
@property (assign, atomic) NSTimeInterval pollingInterval;
@property (strong, nonatomic, readonly, nonnull) NSURLSession *session;
@property (strong, nonatomic, readonly, nonnull) NSURLRequest *originalRequest;
......
......@@ -73,6 +73,8 @@ typedef void (^BUYRequestJSONCompletion)(NSDictionary *json, NSHTTPURLResponse *
{
self = [super init];
if (self) {
self.pollingInterval = 0.3;
_session = session;
_originalRequest = request;
_completion = completion;
......@@ -144,9 +146,16 @@ typedef void (^BUYRequestJSONCompletion)(NSDictionary *json, NSHTTPURLResponse *
* the polling process.
*/
if (self.pollingHandler && self.pollingHandler(json, response, error)) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(self.pollingInterval * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
if (self.isCancelled) {
return;
}
NSURLSessionDataTask *task = [self requestUsingPollingIfNeeded:request completion:completion];
self.runningTask = task;
[task resume];
});
} else {
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