Skip to content

Commit

Permalink
Merge pull request #107 from JamesWrigley/remotechannel-empty
Browse files Browse the repository at this point in the history
Implement Base.isempty(::RemoteChannel)
  • Loading branch information
JamesWrigley authored Dec 2, 2024
2 parents 729ba6a + 8b5983b commit ed12496
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 ed12496

Please sign in to comment.