Skip to content

Commit

Permalink
Merge pull request #3 from JuliaParallel/remotechannel-empty
Browse files Browse the repository at this point in the history
Implement Base.isempty(::RemoteChannel)
  • Loading branch information
jpsamaroo authored Oct 29, 2024
2 parents fd19e68 + 0789d77 commit 76df474
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/src/_changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ This documents notable changes in DistributedNext.jl. The format is based on

## Unreleased

### Fixed
- Fixed behaviour of `isempty(::RemoteChannel)`, which previously had the
side-effect of taking an element from the channel ([#3]).

### Changed
- Added a `project` argument to [`addprocs(::AbstractVector)`](@ref) to specify
the project of a remote worker ([#2]).
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 @@ -493,6 +493,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 76df474

Please sign in to comment.