-
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
Fs interface needs to support context.Context for all API calls #27
Comments
@nt could you point us to an example of a similar project where a Context is used? Would all the Fs functions need a second version where a Context is passed or how would the API look like? |
Here is an example: https://godoc.org/google.golang.org/api/storage/v1#BucketsListCall.Context To generalize your API you would do:
That would allow user implementing a rpc or http handler supporting contexts such as grpc or gorrilla to passit through as is. If the parent call is cancelled, fanned out rpcs to a remote Afero backend can be cancelled as well and resources can be released. This is critical if you want to set deadline on calls and you do not know how long |
I understand the need for this. However most of the backends wouldn't need or be able to use this. One of the initial goals of afero was to be interoperable with the os package as much as possible. Our function signatures mirror that of the os pacakge. This would be a dramatic shift. Additionally wouldn't the Context be better set on the entire Fs rather than per function. This would enable compatibility with current backends. I see Sameer's note in his post that "At Google, we require that Go programmers pass a Context parameter as the first argument to every function on the call path between incoming and outgoing requests.". Just trying to figure out how to incorporate this without breaking everything. |
What about something like this? fs := NewAWSS3FS( /* ... */ ) // good 'ol XMLHttpRequest 😅
afs := &afero.AferoCtx{Fs: fs}
f, err := afs.Context(ctx).Create("foo.txt")
f.Close()
info, err := afs.Context(ctx).Stat("foo.txt") BTW Go's context has been criticized precisely for this :/ |
Proper implementations of Afero for rpc backed filesystems will require passing a context.Context.
See: https://godoc.org/golang.org/x/net/context
The text was updated successfully, but these errors were encountered: