这是indexloc提供的服务,不要输入任何密码
Skip to content

Context should be passed per operation #47

@christian-roggia

Description

@christian-roggia

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions