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

Context should be passed per operation #47

Open
christian-roggia opened this issue Sep 20, 2020 · 0 comments
Open

Context should be passed per operation #47

christian-roggia opened this issue Sep 20, 2020 · 0 comments

Comments

@christian-roggia
Copy link
Contributor

Following the standard patterns for storage and databases written in Golang, the context should be passed per operation and not per connection.

The current setup works in the following way:

cete.NewGRPCClientWithContext(..., ctx)

and Get / Set / Delete / etc. operation are executed this way:

cli.Set(req)

the expected call is the following:

cli.Set(ctx, req)

and this is useful when we want to limit, for example, how long a Set or Get should takes before timing out:

ctx, cancel := context.WithTimeout(ctx, 3*time.Second)
defer cancel()

cli.Set(ctx, req)

this useful to control timeouts, cascade cancellation, and similar operations.

Also, as a final note, the context variable in Golang is normally expected to be the first parameter of the function, this is not a written rule but a very common and popular standard:

cete.NewGRPCClientWithContext(ctx, ...)

See https://golang.org/src/net/dial.go#L369 as an example.

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

No branches or pull requests

1 participant