Skip to content

Commit

Permalink
队列指针持有
Browse files Browse the repository at this point in the history
  • Loading branch information
tbl00c committed Apr 26, 2018
1 parent 5625ac5 commit 02f48e6
Showing 1 changed file with 37 additions and 2 deletions.
39 changes: 37 additions & 2 deletions ZZFlexibleLayoutFramework/ZZFLEXRequestQueue/ZZFLEXRequestQueue.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#import "ZZFLEXRequestQueue.h"
#import "ZZFLEXMacros.h"

static NSMutableArray *__zz_flex_req_array;

#pragma mark - ## ZZFLEXRequestModel
@interface ZZFLEXRequestModel (ZZFLEXRequestQueue)

Expand Down Expand Up @@ -75,10 +77,17 @@ @interface ZZFLEXRequestQueue ()

@property (nonatomic, assign) NSInteger failureCount;

@property (nonatomic, assign) NSInteger pageIndex;

@end

@implementation ZZFLEXRequestQueue

+ (void)load
{
__zz_flex_req_array = [[NSMutableArray alloc] init];
}

- (NSInteger)requestCount
{
return self.queueData.count;
Expand All @@ -100,16 +109,21 @@ - (void)addRequestModel:(ZZFLEXRequestModel *)model

- (void)runAllRequestsWithCompleteAction:(void (^)(NSArray *, NSInteger, NSInteger))completeAction
{
if (_isRuning) {
NSLog(@"[ZZFLEX][WARNING]队列正在执行中...");
return;
}
_isRuning = YES;
self.successCount = 0;
self.failureCount = 0;
self.recData = self.queueData.copy;
self.completeDic = [[NSMutableDictionary alloc] init];
self.completeAction = completeAction;
if (self.queueData.count > 0) {
for (ZZFLEXRequestModel *model in self.queueData) {
[model executeRequestMethod];
if (![__zz_flex_req_array containsObject:self]) {
[__zz_flex_req_array addObject:self];
}
[self p_startRequestRunLoop];
}
else {
if (completeAction) {
Expand All @@ -118,8 +132,26 @@ - (void)runAllRequestsWithCompleteAction:(void (^)(NSArray *, NSInteger, NSInteg
}
}

- (void)p_startRequestRunLoop
{
// if (self.maxRequestCount > 0 && self.queueData.count <= self.requestCount) {
for (ZZFLEXRequestModel *model in self.queueData) {
[model executeRequestMethod];
}
// }
// else {
// for (NSInteger i = 0; i < MIN(self.maxRequestCount, self.requestCount); i++) {
// ZZFLEXRequestModel *model = self.queueData[i];
// [model executeRequestMethod];
// }
// }
}

- (void)cancelAllRequests
{
if ([__zz_flex_req_array containsObject:self]) {
[__zz_flex_req_array removeObject:self];
}
_isRuning = NO;
[self.queueData removeAllObjects];
self.completeDic = nil;
Expand Down Expand Up @@ -158,6 +190,9 @@ - (void)requestCompleteWithResultModel:(ZZFLEXRequestModel *)model
}

if (self.queueData.count == 0) {
if ([__zz_flex_req_array containsObject:self]) {
[__zz_flex_req_array removeObject:self];
}
if (self.successCount + self.failureCount != self.recData.count) {
ZZFLEXLog(@"ZZFLEX request count error");
}
Expand Down

0 comments on commit 02f48e6

Please sign in to comment.