Hallöchen!

The context documentation gives this example:

    // Stream generates values with DoSomething and sends them to out
    // until DoSomething returns an error or ctx.Done is closed.
    func Stream(ctx context.Context, out chan<- Value) error {
        for {
                v, err := DoSomething(ctx)
                if err != nil {
                        return err
                }
                select {
                case <-ctx.Done():
                        return ctx.Err()
                case out <- v:
                }
        }
    }

What if the channel “out” is drained very efficiently?  Then, an
arbitrary number of loop iterations could happen before a
cancellation is detected, couldn’t it?

I would additionally check for ctx.Err() != nil somewhere in the
loop.  Or is there a reason why this is not necessary?

Regards,
Torsten.

-- 
Torsten Bronger

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/87zgbj7maj.fsf%40physik.rwth-aachen.de.

Reply via email to