Function to check if Channel is full

The function isready(ch) checks if Channel ch has any stored value. Is there a function to check if a Channel is full?

There is no function in Base, but you can do it yourself:

isfull(ch::Channel) = length(ch.data) ≥ ch.sz_max

But be aware that isfull is also exported by DataStructures.

1 Like

This fixes the unbuffered channel case:

isfull(ch::Channel) = begin
    if ch.sz_max===0
        isready(ch)
    else
        length(ch.data) ≥ ch.sz_max
    end
end

1 Like

I have given a go at implementing isfull in Implement and export `isfull` by KronosTheLate · Pull Request #53159 · JuliaLang/julia · GitHub, which might be included from Julia 1.11 and onwards.

1 Like