-
Notifications
You must be signed in to change notification settings - Fork 46
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 context.Context as parameter to Download.Start and Cancellation to the main Binary #16
Conversation
Extracting context.Context from the internals of the Download.Start() method as placing it as parameters allows fine graned control over the cancelation Signed-off-by: Dusan Malusev <dusan.998@outlook.com>
I think it will be better if we add ctx, cancel := context.WithCancel(context.Background())
dl, err := got.New(ctx, "http://speedtest.ftp.otenet.gr/files/test10Mb.db", "path")
// ...
dl = &got.Download{
Context: ctx,
} what do you think? I can make the change... (because of BC this will be in v0.2.0) |
I was thinking on this also, but it looked a little bit clunky, we'd need to add nil guard checks pretty much everywhere context was used, but it would be great to have context on |
|
After a little bit of thinking about the problem, (this will make a huge change to structure), we can make dl, err := got.New(got.Config{
Context: context.Background(),
Url: "http://speedtest.ftp.otenet.gr/files/test10Mb.db",
...
})
// Now dl can be interface and got.Download can be private
dl.Start() By doing this, it will allow for more options in the future without breaking backwards compatibility, as more optional options can be added to the Performance implications: |
Yes this is also the good option |
this is also a good idea... func ApproachOne() {
dl, err := got.New(ctx, "https://example.com", "/save/path")
err := dl.Start()
}
func ApproachTwo() {
g := got.New(got.Config{
Context: context.Background(),
Concurrency: 4,
// all other fields except URL and Dest
})
err := g.Download("https://example.com", "/save/path")
} as you can see |
It's good to simplify things now before too many people start using it. |
I have already implemented prototype for the |
Cool thank you :) |
Thank you for the awesome project |
Signed-off-by: Dusan Malusev <dusan.998@outlook.com>
Signed-off-by: Dusan Malusev <dusan.998@outlook.com>
Signed-off-by: Dusan Malusev <dusan.998@outlook.com>
@melbahja There is quite a lot of new changes for the new API, i have finished first part of this draft.
|
opened by mistake |
Extracting context.Context from the internals of the
Download.Start() method as placing it as parameters
allows fine graned control over the cancellation.
This breaks backwards compatibility!
Cancellation to the program in main binary - when system interrupts the program in any way
unfinished download should be removed from the system
Signed-off-by: Dusan Malusev dusan.998@outlook.com