should not return

pull/7/head
Yasuhiro Matsumoto 2017-04-14 19:30:15 +09:00
parent 713996d9d8
commit 98c1da299f
1 changed files with 4 additions and 5 deletions

View File

@ -319,7 +319,7 @@ type Event interface {
event() event()
} }
func handleReader(q chan Event, r io.Reader) error { func handleReader(ctx context.Context, q chan Event, r io.Reader) error {
name := "" name := ""
s := bufio.NewScanner(r) s := bufio.NewScanner(r)
for s.Scan() { for s.Scan() {
@ -335,7 +335,7 @@ func handleReader(q chan Event, r io.Reader) error {
switch name { switch name {
case "update": case "update":
var status Status var status Status
err = json.Unmarshal([]byte(token[1]), &status) err := json.Unmarshal([]byte(token[1]), &status)
if err == nil { if err == nil {
q <- &UpdateEvent{&status} q <- &UpdateEvent{&status}
} }
@ -369,12 +369,11 @@ func (c *Client) StreamingPublic(ctx context.Context) (chan Event, error) {
resp, err = c.Do(req) resp, err = c.Do(req)
} }
if err == nil { if err == nil {
err = handleReader(resp.Body) err = handleReader(ctx, q, resp.Body)
resp.Body.Close()
if err == nil { if err == nil {
break break
} }
resp.Body.Close()
return err
} else { } else {
q <- &ErrorEvent{err} q <- &ErrorEvent{err}
} }