You mean something like this?

func (b *RingBuf) ReadWait(min uint32, timeout time.Duration) bool {

    if min == 0 {

        min = 1

    }

    if b.ReadAvail() >= min {

        return true

    }

    if timeout.Nanoseconds() == 0 {

        return false

    }

    const pollPeriod = 100 * time.Nanosecond

    niter := int64(timeout.Nanoseconds() / pollPeriod.Nanoseconds())


    for i := int64(0); i < niter; i++ {

        if b.ReadAvail() >= min {

            return true

        }

        time.Sleep(pollPeriod)

    }

    return false

}


I think it would be cheaper to call time.Sleep than spinning on 
> runtime.Gosched.

-- 
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