How to iterate over a RemoteChannel?

For regular Channels chan it is ok to do

for val in chan
    @show val
end

but for a RemoteChannel there is no iterate(::RemoteChannel). Is that one missing on purpose? What’s the proper way to spawn a task on a worker that processes all messages coming in via a RemoteChannel until it is closed?

For reference: https://github.com/JuliaLang/julia/issues/31177

As an aside, I think iterating channels is slow because signalling of closed status is via exceptions, so iteration uses a try/catch approach. Perhaps it could be made more performant by returning closed status in some other way.

1 Like