-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Progress reporting functionality #34
base: master
Are you sure you want to change the base?
Changes from 1 commit
fd9e96a
f7360ac
0fc2a55
ecdf098
e37599f
1bb0ef8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -146,15 +146,13 @@ @implementation RXPromise { | |
id _result; | ||
RXPromise_State _state; | ||
|
||
std::list<std::pair<id,promise_progressHandler_t>> *_progressHandlers; | ||
OSSpinLock __volatile _progressSpinLock; | ||
std::list<RXPromise* __weak> *_children; | ||
std::list<std::pair<id,promise_progressHandler_t>> _progressHandlers; | ||
std::list<RXPromise* __weak> _children; | ||
} | ||
|
||
@synthesize result = _result; | ||
@synthesize parent = _parent; | ||
|
||
|
||
|
||
- (void) dealloc { | ||
DLogInfo(@"dealloc: %p", (__bridge void*)self); | ||
if (_handler_queue) { | ||
|
@@ -164,8 +162,6 @@ - (void) dealloc { | |
} | ||
} | ||
void const* key = (__bridge void const*)(self); | ||
delete _progressHandlers; | ||
delete _children; | ||
if (dispatch_get_specific(rxpromise::shared::QueueID) == rxpromise::shared::sync_queue_id) { | ||
Shared.assocs.erase(key); | ||
} else { | ||
|
@@ -357,10 +353,8 @@ - (void)synced_updateWithProgress:(float)progress { | |
if (_state != Pending) { | ||
return; | ||
} | ||
OSSpinLockLock(&_progressSpinLock); | ||
_progressValue = progress; | ||
if (_progressHandlers) { | ||
for (const std::pair<id, promise_progressHandler_t> handlerPair : *_progressHandlers) { | ||
if (_progressHandlers.size()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The enclosing if-statement |
||
for (const std::pair<id, promise_progressHandler_t> handlerPair : _progressHandlers) { | ||
id executionContext = handlerPair.first; | ||
promise_progressHandler_t handlerBlock = handlerPair.second; | ||
if (executionContext == Shared.default_concurrent_queue) { | ||
|
@@ -380,12 +374,11 @@ - (void)synced_updateWithProgress:(float)progress { | |
} | ||
} | ||
} | ||
if (_children) { | ||
for(const RXPromise * __weak child : *_children) { | ||
if (_children.size()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The enclosing if-statment IFF
Then lines 447 till 456 can be deleted:
Original source: https://github.com/couchdeveloper/RXPromise/blob/master/RXPromise%20Libraries/Source/RXPromise.mm#L402-L411 |
||
for(const RXPromise * __weak child : _children) { | ||
[child updateWithProgress:progress]; | ||
} | ||
} | ||
OSSpinLockUnlock(&_progressSpinLock); | ||
} | ||
|
||
|
||
|
@@ -412,20 +405,12 @@ - (instancetype) registerWithExecutionContext:(id)executionContext | |
if (_handler_queue == nil) { | ||
_handler_queue = createHandlerQueue(_state == Pending, (__bridge void*)self); | ||
} | ||
OSSpinLockLock(&_progressSpinLock); | ||
if (onProgress) { | ||
if (!_progressHandlers) { | ||
_progressHandlers = new std::list<std::pair<id, promise_progressHandler_t>>(); | ||
} | ||
_progressHandlers->push_back({executionContext, onProgress}); | ||
} | ||
if (!_children) { | ||
_children = new std::list<RXPromise* __weak>(); | ||
_progressHandlers.push_back({executionContext, onProgress}); | ||
} | ||
if (weakReturnedPromise) { | ||
_children->push_back(weakReturnedPromise); | ||
_children.push_back(weakReturnedPromise); | ||
} | ||
OSSpinLockUnlock(&_progressSpinLock); | ||
|
||
// Finally, *enqueue* a wrapper block which eventually gets invoked when the | ||
// promise will be resolved: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ivar
_children
can possibly be omitted. Please read my comments, and verify my assumptions.