Skip to content

Commit

Permalink
Merge pull request #44 from AQAquamarine/fix/operation_already_start
Browse files Browse the repository at this point in the history
NSOpration: receiver already executing となる不具合を修正
  • Loading branch information
kaiinui committed Jan 29, 2015
2 parents e18bc65 + 31fceba commit 5031d93
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
11 changes: 5 additions & 6 deletions Aquasync/Classes/AQAquaSyncPullSyncOperation.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,10 @@ - (instancetype)initWithSyncableObjectAggregator:(id<AQSyncableObjectAggregator>
# pragma mark - NSOperation

- (void)start {
if (self.failTimer) {
[self.failTimer invalidate];
self.failTimer = nil;
}

[self performOperation];
}

- (void)performOperation {
__weak typeof(self) weakSelf = self;
NSInteger UST = [self.syncableObjectAggregator UST];
NSString *deviceToken = [self.syncableObjectAggregator deviceToken];
Expand Down Expand Up @@ -89,7 +88,7 @@ - (void)didFailWithError:(NSError *)error {
self.failCount += 1;

NSTimeInterval interval = [self waitForFailCount:self.failCount];
self.failTimer = [NSTimer scheduledTimerWithTimeInterval:interval target:self selector:@selector(start) userInfo:nil repeats:NO];
self.failTimer = [NSTimer scheduledTimerWithTimeInterval:interval target:self selector:@selector(performOperation) userInfo:nil repeats:NO];
}

- (void)failOperationWithError:(NSError *)error {
Expand Down
13 changes: 6 additions & 7 deletions Aquasync/Classes/AQAquaSyncPushSyncOperation.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,11 @@ - (instancetype)initWithSyncableObjectAggregator:(id<AQSyncableObjectAggregator>

# pragma mark - NSOperation

- (void)main {
if (self.failTimer) {
[self.failTimer invalidate];
self.failTimer = nil;
}

- (void)start {
[self performOperation];
}

- (void)performOperation {
AQDeltaPack *deltaPack = [self.syncableObjectAggregator deltaPackForSynchronization];
__weak typeof(self) weakSelf = self;
[self.client pushDeltaPack:deltaPack success:^(id response) {
Expand Down Expand Up @@ -86,7 +85,7 @@ - (void)didFailWithError:(NSError *)error {
self.failCount += 1;

NSTimeInterval interval = [self waitForFailCount:self.failCount];
self.failTimer = [NSTimer scheduledTimerWithTimeInterval:interval target:self selector:@selector(start) userInfo:nil repeats:NO];
self.failTimer = [NSTimer scheduledTimerWithTimeInterval:interval target:self selector:@selector(performOperation) userInfo:nil repeats:NO];
}

- (void)failOperationWithError:(NSError *)error {
Expand Down

0 comments on commit 5031d93

Please sign in to comment.