aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/objective-c/RxLibrary/GRXConcurrentWriteable.m
diff options
context:
space:
mode:
authorGravatar Muxi Yan <mxyan@google.com>2018-02-05 09:52:33 -0800
committerGravatar Muxi Yan <mxyan@google.com>2018-02-05 09:52:33 -0800
commitd65458dde865deecf101cdd5434343b4ae41e7e6 (patch)
treed067f4b6960c85c68ceac6c92de7d1d845f90c63 /src/objective-c/RxLibrary/GRXConcurrentWriteable.m
parentb1f5d59b4fb567cdcc6786122d7bfcbd698f9af0 (diff)
Fix reference of self in block
Diffstat (limited to 'src/objective-c/RxLibrary/GRXConcurrentWriteable.m')
-rw-r--r--src/objective-c/RxLibrary/GRXConcurrentWriteable.m30
1 files changed, 17 insertions, 13 deletions
diff --git a/src/objective-c/RxLibrary/GRXConcurrentWriteable.m b/src/objective-c/RxLibrary/GRXConcurrentWriteable.m
index 37bc975f87..dc801bede8 100644
--- a/src/objective-c/RxLibrary/GRXConcurrentWriteable.m
+++ b/src/objective-c/RxLibrary/GRXConcurrentWriteable.m
@@ -64,21 +64,25 @@
}
- (void)enqueueSuccessfulCompletion {
+ __weak typeof(self) weakSelf = self;
dispatch_async(_writeableQueue, ^{
- BOOL finished = NO;
- @synchronized (self) {
- if (!_alreadyFinished) {
- _alreadyFinished = YES;
- } else {
- finished = YES;
+ typeof(self) strongSelf = self;
+ if (strongSelf) {
+ BOOL finished = NO;
+ @synchronized (self) {
+ if (!strongSelf->_alreadyFinished) {
+ strongSelf->_alreadyFinished = YES;
+ } else {
+ finished = YES;
+ }
+ }
+ if (!finished) {
+ // Cancellation is now impossible. None of the other three blocks can run concurrently with
+ // this one.
+ [self.writeable writesFinishedWithError:nil];
+ // Skip any possible message to the wrapped writeable enqueued after this one.
+ self.writeable = nil;
}
- }
- if (!finished) {
- // Cancellation is now impossible. None of the other three blocks can run concurrently with
- // this one.
- [self.writeable writesFinishedWithError:nil];
- // Skip any possible message to the wrapped writeable enqueued after this one.
- self.writeable = nil;
}
});
}