-
Notifications
You must be signed in to change notification settings - Fork 514
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
Adding support for automatically skipping cancelation if the amount l… #364
Conversation
…eft to be downloaded is less than the average time to first byte.
🚫 CI failed with log |
🚫 CI failed with log |
break; | ||
|
||
case NSURLSessionTaskStateCompleted: | ||
NSAssert(self.startTime != 0, @"Expect that task was started before it's completed."); |
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.
I might say > 0
here.
@@ -35,6 +35,8 @@ typedef void (^PINURLSessionDataTaskCompletion)(NSURLSessionTask * _Nonnull task | |||
|
|||
@property (atomic, weak, nullable) id <PINURLSessionManagerDelegate> delegate; | |||
|
|||
- (NSTimeInterval)weightedTimeToFirstByteForHost:(nonnull NSString *)host; |
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.
This would benefit from a brief documentation comment.
if (metric.requestStartDate == nil || metric.responseStartDate == nil) { | ||
//Only evaluate requests which completed their first byte. | ||
valid = NO; | ||
break; |
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.
Seems like you could drop the valid
flag and just return
here.
NSTimeInterval timeToFirstByte; | ||
[self lock]; | ||
timeToFirstByte = [[_timeToFirstByteCache objectForKey:host] doubleValue]; | ||
if (timeToFirstByte <= 0 + DBL_EPSILON) { |
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.
You can drop the lock earlier (here).
|
||
- (void)storeTimeToFirstByte:(NSTimeInterval)timeToFirstByte forHost:(NSString *)host | ||
{ | ||
[self lock]; |
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.
I wonder if you can get away without locking. NSCache
supports concurrent access, and the logic below is sufficiently fuzzy that missing/overwriting a measurement probably won't be super meaningful.
…eft to be downloaded is less than the average time to first byte.
Putting this up in favor of #357