[ 
https://issues.apache.org/jira/browse/THRIFT-4236?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16062841#comment-16062841
 ] 

taozle commented on THRIFT-4236:
--------------------------------

I don't think the {{THeaderTransport}} is what i want.

The {{context}} that i mentioned above is the library {{context}} officially 
accepted in go1.7 which previously located at {{golang.org/x/net/context}}.
Currently, the thrift definition:
{code:java}
service HelloService {
    string ping()
}
{code}
will generate code like this:
{code:java}
type HelloService interface {
  Ping() (r string, err error)
}
{code}
other framework like grpc will pass a {{context}} for the first param, so the 
expected output for above definition may looks like:
{code:java}
type HelloService interface {
  Ping(ctx Context) (r string, err error)
}
{code}
Adding the {{context}} we can return immediately if current request is already 
expired:
{code:java}
func (h *HelloHandler) Ping(ctx Context) {
    f, cancer := CreateLongTask()
    rv = make(chan string)
    go f(rv) // long task

    select {
    case <-ctx.Done():
        cancer()
        return // Timeout!
    case <-rv:
        // Another heavy work.
    }
}
{code}
or carry extra info like zipkin span for framework level usage.

> Support context in go generated code.
> -------------------------------------
>
>                 Key: THRIFT-4236
>                 URL: https://issues.apache.org/jira/browse/THRIFT-4236
>             Project: Thrift
>          Issue Type: Improvement
>          Components: Go - Compiler, Go - Library
>            Reporter: taozle
>
> Since context is widely used in go's community, and there is lots of 
> advantage to use context such as control timeout, carry extra info in one 
> request etc, so is there any plan for this? i just searched the issues but 
> didn't find anything about this.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to