Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The Len() of InfiniteChannel is incorrect #24

Open
vegertar opened this issue Jul 30, 2016 · 2 comments
Open

The Len() of InfiniteChannel is incorrect #24

vegertar opened this issue Jul 30, 2016 · 2 comments
Labels

Comments

@vegertar
Copy link

When I use InfiniteChannel, I found that Len() returned is a "case" buffered value, https://github.com/eapache/channels/blob/master/infinite_channel.go#L58

A little demo shown as bellow:

package main

import (
    "fmt"
    "github.com/eapache/channels"
)

func main() {
    ch := make(chan int)
    infiniteCh := channels.NewInfiniteChannel()
    channels.Unwrap(infiniteCh, ch)

    for i := 0; i < 1000; i++ {
        infiniteCh.In() <- i
    }
    infiniteCh.Close()
    fmt.Println(infiniteCh.Len())

    m := 0
    for _ = range ch {
        m += 1
    }
    fmt.Println(m)
}

The output is

999
1000

It seems like we cannot simply place an expression in blocking evaluation context.

@vegertar
Copy link
Author

BTW, I have noticed #18 also, but I think they aren't the same problem.

@eapache eapache added the bug label Jul 30, 2016
@eapache
Copy link
Owner

eapache commented Jul 30, 2016

The problem is actually in the implementation of Unwrap which unconditional reads from the input channel before it may be able to write. I don't know if it is possible to fix off the top of my head.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants