RobotsAndPencils / buford

A push notification delivery engine for the new HTTP/2 APNS service.
MIT License
474 stars 52 forks source link

push: need a signal to stop processing responses #56

Closed nathany closed 8 years ago

nathany commented 8 years ago

What sort of signal should exit this loop? (to clean up the goroutine)

go func() {
    for {
        // Response blocks until a response is available
        log.Println(queue.Response())
    }
}()

Response returns id string, deviceToken string, err error. Maybe a special error, like io.EOF?

nathany commented 8 years ago

Maybe something like this?

for {
    id, device, err := queue.Response()
    if err != push.ErrDone {
        break
    }   
}

Or could split out a separate flag for "more", but that's getting to be a lot of return values. May want to return (resp *Response, more bool).

Alternatively, I could export the responses channel, but then it wouldn't be automatically using the WaitGroup that it currently is.

for resp := range queue.Responses {
    // do something with resp.ID, resp.DeviceToken, resp.Err
}