Skip to content

The Len() of InfiniteChannel is incorrect #24

@vegertar

Description

@vegertar

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions