Skip to content
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

Add support for canceling a download if the expected time to complete… #357

Closed
wants to merge 3 commits into from

Conversation

garrettmoon
Copy link
Collaborator

… is less than provided value.

if (self.sessionTaskEndTime > 0) {
return 0;
}
CFTimeInterval taskLength = CACurrentMediaTime() - self.sessionTaskStartTime;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe call this elapsedTime?

cache and used to resume the download if the same URL is attempted to be downloaded in the future.
*/

- (void)cancelTaskWithUUID:(nonnull NSUUID *)UUID ifExpectedToExceedTimeInterval:(NSTimeInterval)timeToExceed storeResumeData:(BOOL)storeResumeData;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This time interval is assumed to be relative to "now" when it's provided but won't be evaluated until some (small) time in the future.

Might be better (clearer and more predictable) for this to take an absolute "deadline" time beyond which any longer-running tasks are cancelled.

I know precision here is sloppy because it's all based on estimates, but it still might be a better API overall.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't decide on this. My thought is that if you're using this API, you want to cancel something unless it's got just a bit left to download.

Here's the scenario I imagine:

  • At time 0 you ask to cancel a download if it doesn't complete in the next 100ms
  • At time 100ms, the cancel request is serviced and the image has 50ms left to download

In that case, what do we think the caller would want? If we are provided an absolute time, the image will continue to download until there is 50ms left and then be canceled. If we provide a relative time, the image will be downloaded until there is 50ms left and be allowed to continue.

I think I would rather specify this as an interval because I care about how much time is left when the cancelation occurs, not when I call the method?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, any better ideas on naming here? It's currently very atrocious :D

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see your point. On one hand, we're "asking" PINRemoteImage to save us some network bandwidth based on best effort measurements. On the other, we believe the caller has a specific plan of action, and part of that plan involves dropping in-flight network requests.

Relatedly, would it be helpful to think of this as a "suspend" operation rather than a "cancel" operation?

Copy link
Member

@nguyenhuy nguyenhuy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I second Jon's comments. Can't wait to use this new API!

@@ -113,4 +115,21 @@ - (nonnull PINRemoteImageManagerResult *)imageResultWithImage:(nullable PINImage
bytesSavedByResuming:bytesSavedByResuming];
}

- (CFTimeInterval)expectedSecondsLeftToComplete
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CFTimeInterval is always in seconds. Maybe expectedTimeLeftToComplete?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

estimatedTimeRemaining ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooh, way better (I was relying on this review to fix my horrible naming)

@ghost
Copy link

ghost commented May 17, 2017

1 Warning
⚠️ Any source code changes should have an entry in CHANGELOG.md or have #trivial in their title.

Generated by 🚫 Danger

@garrettmoon
Copy link
Collaborator Author

Closing in favor of #364

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants