Skip to content

Commit

Permalink
Implement Base.isempty(::RemoteChannel)
Browse files Browse the repository at this point in the history
The default method from Base has the nasty side-effect of take!()'ing from the
underlying channel.
  • Loading branch information
JamesWrigley committed Aug 3, 2024
1 parent 6a0383b commit 8537424
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/remotecall.jl
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,9 @@ close(rr::RemoteChannel) = call_on_owner(close_ref, rr)
isopen_ref(rid) = isopen(lookup_ref(rid).c)
isopen(rr::RemoteChannel) = call_on_owner(isopen_ref, rr)

isempty_ref(rid) = isempty(lookup_ref(rid).c)
Base.isempty(rr::RemoteChannel) = call_on_owner(isempty_ref, rr)

getindex(r::RemoteChannel) = fetch(r)
getindex(r::Future) = fetch(r)

Expand Down
12 changes: 12 additions & 0 deletions test/distributed_exec.jl
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,18 @@ let ch = RemoteChannel(() -> Channel(1))
@test 10 == test_iteration_collect(ch)
end

# Test isempty(::RemoteChannel). This should not modify the underlying
# AbstractChannel, which Base's default implementation will do.
let
chan = Channel(1)
push!(chan, 1)
remotechan = RemoteChannel(() -> chan)

@test !isempty(remotechan)
# Calling `isempty(remotechan)` shouldn't have modified `chan`
@test !isempty(chan)
end

# make sure exceptions propagate when waiting on Tasks
@test_throws CompositeException (@sync (@async error("oops")))
try
Expand Down

0 comments on commit 8537424

Please sign in to comment.