smallnest / chanx

unbounded chan
MIT License
431 stars 63 forks source link

Why is Len() not accurate ? #20

Open bruceauyeung opened 1 week ago

bruceauyeung commented 1 week ago
// Len returns len of In plus len of Out plus len of buffer.
// It is not accurate and only for your evaluating approximate number of elements in this chan,
func (c *UnboundedChan[T]) Len() int {
    return len(c.In) + c.BufLen() + len(c.Out)
}

And if i wanna check whether this chan is empty or not, how should i do ?

smallnest commented 6 days ago

because the dim of the three values is not atomic

bruceauyeung commented 4 days ago

because the dim of the three values is not atomic

Alright then. But at last, if chan is consumed out and no more values pushed in, Len() will be 0, right?

smallnest commented 4 days ago

because the dim of the three values is not atomic

Alright then. But at last, if chan is consumed out and no more values pushed in, Len() will be 0, right?

yes