-
Notifications
You must be signed in to change notification settings - Fork 383
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
Consider passing Options
to all Client methods
#7198
Comments
(mostly repeating what @devjgm, but maybe adding an original thought or two) OverviewThis would offer a general framework for implementing a solution to something like #4926. (In addition to timeouts, it could be used to add Metadata, serve some service specific function, etc.). The // calls like:
Status Foo(FooRequest const& request);
// ...become:
Status Foo(FooRequest const& request, Options const& options = {}); The Details / Open QuestionsJotting down some thoughts from a previous discussion with the team:
While we probably have enough direction to start implementing the API surface, I think we need a clearer picture of what a per-call option implementation looks like.
AppendixJust to give an idea of what I currently have in mind (setting deadlines) (for gRPC): /// FILE: google/cloud/common_options.h
namespace google::cloud {
struct DeadlineOption {
using Type = std::chrono::time_point<std::chrono::system_clock>;
};
} // namespace
/// FILE: google/cloud/grpc_options.h
namespace google::cloud::internal {
struct GrpcSetupOption {
using Type = std::function<void(grpc::ClientContext&)>;
};
// TODO : Whether this alters a ClientContext& or returns a new, configured
// ClientContext can be figured out at a later date.
void ConfigureContext(grpc::ClientContext& context, Options const& opts) {
// TODO : Which option takes precedence, and whether they are exclusive
// can be decided later.
if (opts.has<GrpcSetupOption>()) {
opts.get<GrpcSetupOption>()(context);
} else if (opts.has<DeadlineOption>()) {
context.set_deadline(opts.get<DeadlineOption>());
}
}
} // namespace |
For the record, I currently have #7669 out for review, which adds the notion of "call-tree-specific options" (you can call it "context" if you like). And then I have a PR queued up behind that which adds the
In that world this is no longer necessary, which removes many of the open questions above. |
This is implemented for generated libraries, and we have separate bugs for each library. |
See #8164 |
(filing an issue so we don't forget about this)
We sometimes need to the ability to pass method-specific options to a client function call. For example:
google-cloud-cpp/google/cloud/spanner/client.h
Lines 250 to 253 in 0b2f1e5
Rather than having a bunch of separate options classes, we may just want to pass a
google::cloud::Options opts = {}
argument as the last argument to all client methods. This would help us be future-proof as it would let us add more options to a method call without breaking existing calls.We could use something like this to add per-method timeouts.
We may want to call this
Context
rather thanOptions
if there's a meaningful semantic difference between the two.We'll need to do this in the generator too.
The text was updated successfully, but these errors were encountered: