Skip to content

Commit ed12496

Browse files
authored
Merge pull request #107 from JamesWrigley/remotechannel-empty
Implement Base.isempty(::RemoteChannel)
2 parents 729ba6a + 8b5983b commit ed12496

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/remotecall.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,9 @@ close(rr::RemoteChannel) = call_on_owner(close_ref, rr)
768768
isopen_ref(rid) = isopen(lookup_ref(rid).c)
769769
isopen(rr::RemoteChannel) = call_on_owner(isopen_ref, rr)
770770

771+
isempty_ref(rid) = isempty(lookup_ref(rid).c)
772+
Base.isempty(rr::RemoteChannel) = call_on_owner(isempty_ref, rr)
773+
771774
getindex(r::RemoteChannel) = fetch(r)
772775
getindex(r::Future) = fetch(r)
773776

test/distributed_exec.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,18 @@ let ch = RemoteChannel(() -> Channel(1))
497497
@test 10 == test_iteration_collect(ch)
498498
end
499499

500+
# Test isempty(::RemoteChannel). This should not modify the underlying
501+
# AbstractChannel, which Base's default implementation will do.
502+
let
503+
chan = Channel(1)
504+
push!(chan, 1)
505+
remotechan = RemoteChannel(() -> chan)
506+
507+
@test !isempty(remotechan)
508+
# Calling `isempty(remotechan)` shouldn't have modified `chan`
509+
@test !isempty(chan)
510+
end
511+
500512
# make sure exceptions propagate when waiting on Tasks
501513
@test_throws CompositeException (@sync (@async error("oops")))
502514
try

0 commit comments

Comments
 (0)