Skip to content

Commit 76df474

Browse files
authored
Merge pull request #3 from JuliaParallel/remotechannel-empty
Implement Base.isempty(::RemoteChannel)
2 parents fd19e68 + 0789d77 commit 76df474

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

docs/src/_changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ This documents notable changes in DistributedNext.jl. The format is based on
99

1010
## Unreleased
1111

12+
### Fixed
13+
- Fixed behaviour of `isempty(::RemoteChannel)`, which previously had the
14+
side-effect of taking an element from the channel ([#3]).
15+
1216
### Changed
1317
- Added a `project` argument to [`addprocs(::AbstractVector)`](@ref) to specify
1418
the project of a remote worker ([#2]).

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
@@ -493,6 +493,18 @@ let ch = RemoteChannel(() -> Channel(1))
493493
@test 10 == test_iteration_collect(ch)
494494
end
495495

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

0 commit comments

Comments
 (0)