Dear Jakob and all,

indeed I was blind. This works like a charm:
    amount := 42
    remaining := amount
    ticker := time.NewTicker(5 * time.Second)
    defer ticker.Stop()
    for remaining > 0 {
        select {
        case <-ticker.C:
            fmt.Printf("Progress: %d left from %d\n", remaining, amount)
        case <-donChan:
            remaining--
        case res := <-resChan:
            fmt.Println(res)
        }
    }

thanks all!
Chris

On Saturday, May 19, 2018 at 9:16:19 PM UTC+2, Jakob Borg wrote:
>
> On 19 May 2018, at 16:25, Chris Burkert <burker...@gmail.com <javascript:>> 
> wrote: 
> > 
> > case <-time.After(5 * time.Second): 
> >             fmt.Printf("Progress: %d left from %d\n", remaining, amount) 
>
> It's not super clear from your post if you're aware of this already, but 
> this case will only fire after the select has been blocked for five 
> seconds. If there is any activity on the other cases one of those will 
> proceed, you'll get another loop iteration, and another five second timeout 
> before status output. 
>
> Typically you'd use a five second ticker instead to get a channel event 
> every five seconds and use that to print status output. 
>
> //jb

-- 
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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to