Crystal Channel doesn’t expose such API. Generally capacity applies to buffered channels only, where it represents the number of elements channel can hold, and it shouldn’t be confused with size. I don’t know what would be the use case where you would require such information, but you can get this info by monkey patching the Channel class.
Note: Monkey patching stdlib isn’t a good practice and is something which should be applied with extreme caution.
class Channel(T)
def capacity : Int32
(queue = @queue) ? queue.@capacity : 0
end
end
Yeah, sure it will be good to raise a feature request and have it open for discussion, and see if community and/or core team agrees to extend Channel class to add some api which Returns Maximum capacity of the Channel.
I could imagine 1 use case would be gathering/monitoring channel metrics, and maybe automating channel capacity or spawning more process w/ more channels, depending on demand.