Merge pull request #1310 from maicki/UpdateCommittedAPI

[ASCollection/TableView] Add -waitUntilAllUpdatesAreCommitted to wait for concurrent measurement to finish
This commit is contained in:
appleguy 2016-03-02 20:19:19 -08:00
commit edd567a91d
7 changed files with 48 additions and 7 deletions

View File

@ -165,6 +165,11 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (void)reloadDataImmediately;
/**
* Blocks execution of the main thread until all section and row updates are committed. This method must be called from the main thread.
*/
- (void)waitUntilAllUpdatesAreCommitted;
/**
* Registers the given kind of supplementary node for use in creating node-backed supplementary views.
*

View File

@ -268,6 +268,12 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
[super reloadData];
}
- (void)waitUntilAllUpdatesAreCommitted
{
ASDisplayNodeAssertMainThread();
[_dataController waitUntilAllUpdatesAreCommitted];
}
- (void)setDataSource:(id<UICollectionViewDataSource>)dataSource
{
// UIKit can internally generate a call to this method upon changing the asyncDataSource; only assert for non-nil.

View File

@ -163,6 +163,11 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (void)endUpdatesAnimated:(BOOL)animated completion:(void (^ _Nullable)(BOOL completed))completion;
/**
* Blocks execution of the main thread until all section and row updates are committed. This method must be called from the main thread.
*/
- (void)waitUntilAllUpdatesAreCommitted;
/**
* Inserts one or more sections, with an option to animate the insertion.
*

View File

@ -394,6 +394,12 @@ static NSString * const kCellReuseIdentifier = @"_ASTableViewCell";
[_dataController endUpdatesAnimated:animated completion:completion];
}
- (void)waitUntilAllUpdatesAreCommitted
{
ASDisplayNodeAssertMainThread();
[_dataController waitUntilAllUpdatesAreCommitted];
}
- (void)layoutSubviews
{
if (_nodesConstrainedWidth != self.bounds.size.width) {

View File

@ -15,7 +15,7 @@
@interface ASChangeSetDataController ()
@property (nonatomic, assign) NSUInteger batchUpdateCounter;
@property (nonatomic, assign) NSUInteger changeSetBatchUpdateCounter;
@property (nonatomic, strong) _ASHierarchyChangeSet *changeSet;
@end
@ -28,7 +28,7 @@
return nil;
}
_batchUpdateCounter = 0;
_changeSetBatchUpdateCounter = 0;
return self;
}
@ -38,18 +38,18 @@
- (void)beginUpdates
{
ASDisplayNodeAssertMainThread();
if (_batchUpdateCounter == 0) {
if (_changeSetBatchUpdateCounter == 0) {
_changeSet = [_ASHierarchyChangeSet new];
}
_batchUpdateCounter++;
_changeSetBatchUpdateCounter++;
}
- (void)endUpdatesAnimated:(BOOL)animated completion:(void (^)(BOOL))completion
{
ASDisplayNodeAssertMainThread();
_batchUpdateCounter--;
_changeSetBatchUpdateCounter--;
if (_batchUpdateCounter == 0) {
if (_changeSetBatchUpdateCounter == 0) {
[_changeSet markCompleted];
[super beginUpdates];
@ -86,7 +86,7 @@
- (BOOL)batchUpdating
{
BOOL batchUpdating = (_batchUpdateCounter != 0);
BOOL batchUpdating = (_changeSetBatchUpdateCounter != 0);
// _changeSet must be available during batch update
ASDisplayNodeAssertTrue(batchUpdating == (_changeSet != nil));
return batchUpdating;

View File

@ -181,6 +181,8 @@ FOUNDATION_EXPORT NSString * const ASDataControllerRowNodeKind;
- (void)reloadDataImmediatelyWithAnimationOptions:(ASDataControllerAnimationOptions)animationOptions;
- (void)waitUntilAllUpdatesAreCommitted;
/** @name Data Querying */
- (NSUInteger)numberOfSections;

View File

@ -462,6 +462,23 @@ static void *kASSizingQueueContext = &kASSizingQueueContext;
}];
}
- (void)waitUntilAllUpdatesAreCommitted
{
ASDisplayNodeAssertMainThread();
ASDisplayNodeAssert(_batchUpdateCounter == 0, @"Should not be called between beginUpdate or endUpdate");
// This should never be called in a batch update, return immediately therefore
if (_batchUpdateCounter > 0) { return; }
[_editingTransactionQueue waitUntilAllOperationsAreFinished];
// Schedule block in main serial queue to wait until all operations are finished that are
// where scheduled while waiting for the _editingTransactionQueue to finish
[_mainSerialQueue performBlockOnMainThread:^{
ASDisplayNodeAssert(_editingTransactionQueue.operationCount == 0, @"No operation should be in the _editingTransactionQueue anymore");
}];
}
#pragma mark - Data Source Access (Calling _dataSource)
/**