-
Notifications
You must be signed in to change notification settings - Fork 27
Open
Description
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.
Metadata
Metadata
Assignees
Labels
No labels