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

Allow application to set the read deadline when reading the response body #2

Closed
garyburd opened this issue Jul 23, 2013 · 0 comments
Closed

Comments

@garyburd
Copy link

If an application can specify the read deadline when reading the response body, then the application can easily detect dropped connections for Twitter streaming endpoints and similar services.

The following snippet of code shows how an application can use the feature. The Twitter streaming endpoints write a blank keep alive line very 30 seconds.

scanner := bufio.NewScanner(body)
body.SetReadDeadline(time.Now().Add(40 * time.Second))
for scanner.Scan() {
    p := scanner.Bytes()
    if len(p) > 0 {
        processTweet(p)
    }
   body.SetReadDeadline(time.Now().Add(40 * time.Second))
}
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

2 participants